Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- num_pow2:
- addi $sp, $sp, -16 # alloco lo stack
- sw $ra, 12($sp) # salvo $ra
- sw $s0, 8($sp)
- sw $s1, 4($sp)
- sw $s2, 0($sp)
- add $s0, $a0, $0 # $s0 = &A[0]
- add $s1, $0, $0 # $s1 = 0 = pow2_counter
- sll $s2, $a1, 2 # $s2 = m*4
- add $s2, $a0, $s2 # $s2 = ( &A[0] + (m*4) ) = &A[m]
- for: beq $s0, $s2, exit # iff $s0 == &A[m] goto exit
- lw $a0, 0($s0) # $a0 = A[i]
- jal pow2
- beq $v0, $0, else # iff $v0 == 0 ==> A[i] non è una potenza di due
- addi $s1, $s1, 1 # iff $v0 != 0 ===> A[i] è una potenza di due e allora: pow2_counter++
- else: addi $s0, $s0, 4 # A++
- j for
- exit: add $v0, $0, $s1 # return $v0 = pow2_counter
- lw $s2, 0($sp)
- lw $s1, 4($sp)
- lw $s0, 8($sp)
- lw $ra, 12($sp) # ripristino $ra
- addi $sp, $sp, 16 # dealloco stack
- jr $ra
Add Comment
Please, Sign In to add comment