Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # $s1 = &A1[0]
- # $s2 = &A2[0]
- # $s3 = sum even numbers
- add $t0, $zero, $zero # A1_counter
- add $t1, $zero, $zero # A2_counter
- add $s3, $zero, $zero # sum = 0
- addi $t4, 7
- loop_start:
- sll $t2, $t0, 2 # $t2 = A1_counter * 4
- sll $t3, $t1, 2 # $t3 = A2_counter * 4
- add $t2, $t2, $s1 # $t2 = &A1[0] + A1_counter * 4 i.e &A1[i]
- add $t3, $t3, $s2 # $t2 = &A2[0] + A2_counter * 4 i.e &A2[i[
- # condition check
- lw $s0, 0($t2) # $s0 = A1[i]
- beq $s0, $zero, exit
- # procedure call
- mov $a0, $s0
- jal is_even
- if_number_is_even_start:
- # condition
- bne $v0, 1, if_number_is_even_end:
- # true evaluation
- add $s3, $s3, $s0 # sum += A1[i]
- if_number_is_even_end:
- if_number_ends_with_ones_start:
- # condition
- and $t5, $s0, $t4
- bne $t5, $t4 # jump if (A[i] & 7) != 7
- # true evaluation
- sw $s0, 0($t3) # A2[j] = A1[i]
- addi $t1, $t1, 1 # ++j
- if_number_ends_with_ones_end:
- addi $t0, $t0, 1 # ++i
- j loop_start
- loop_end:
- is_even:
- addi $t7, $zero, 2
- div $a0, $t0
- mfhi $t0
- if_remainder_is_zero:
- #condition
- bne $t7, $zero, else
- # return 1
- addi $v0, $zero, 1
- jr $ra
- else:
- # return 0
- addi $v0, $zero, $zero
- jr $ra
- exit:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement