Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data 0x10000000
- num: .word 11288511
- is_mirror: .byte 0
- num_digits: .word 0
- mirror_val: .byte 0,1,5,'x','x',2,'x','x',8,'x'
- .globl __start
- .text 0x00400000
- __start: la $t0,num
- lw $t0,0($t0) # N
- ## Extract digits in $t2 ##
- li $s0,0 # Counter
- move $t3,$t0 # Take aux from num
- li $t2,10 # Save 10 constant
- $L1: div $t3,$t2 # Num / 10
- mflo $t3 # Mov quocient to aux
- addi $s0,$s0,1 # Increment digit counter
- bnez $t3,$L1
- la $t3,num_digits
- sw $s0,0($t3) # Save digit counter
- ## Mirror process ##
- move $t1,$s0 # $t1 = c (length)
- li $t3,1 # $t3 = control signal (0->Not mirror,1->Mirror)
- $L2: div $t0,$t2 # num%10 ( While num > 9 -has more than one digit- )
- mfhi $s0 # take remainder from hi
- addiu $t1,$t1,-1 # to calculate this pow, it's necessary to rest 1 to $t1 (length)
- jal $PowTen
- addiu $t1,$t1,1 # restore length
- move $s1,$v0 # s1 = (10**(c-1))
- div $t0,$s1 # n/(10**(c-1))
- mflo $s1 # s1 = n/10**(c-1)
- la $s2,mirror_val
- add $s2,$s2,$s1 # mirror_val offset to read byte
- lb $s1,0($s2) # s1 = mirrored value
- bne $s1,$s0,$EndFalse # if n%10 != mirror[n/(10**(c-1))]
- div $t0,$t2 # n /= 10
- mflo $t0 # t0 = t0 / 10
- addi $t1,$t1,-2 # $t1 -= 2 (c-2)
- jal $PowTen # (10**(c-2))
- move $s1,$v0 # s1 = (10**(c-2))
- li $s3,9 # 9 constant
- bgt $t0,$s3,$L2 # if num < 10
- ## if comes here, is equal in mirror ##
- li $t0,1
- la $t1,is_mirror
- sb $t0,0($t1)
- jal exit
- $EndFalse: li $t0,0
- la $t1,is_mirror
- sb $t0,0($t1) # control signal = 0 -> X
- jal exit
- ## Pow 10 ##
- $PowTen: move $a0,$t1 # Save length for counter
- li $s1,10
- $LPT: mult $s1,$t2 # $s1 = 10*10
- mflo $s1 # $s1 = 10*10
- addi $a0,$a0,-1 # Dec counter
- bnez $a0,$LPT
- move $v0,$s1
- jr $ra
- ## Exit ##
- exit: li $v0,10
- syscall
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement