Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1.  
  2. # $s1 = &A1[0]
  3. # $s2 = &A2[0]
  4. # $s3 = sum even numbers
  5.  
  6. add $t0, $zero, $zero # A1_counter
  7. add $t1, $zero, $zero # A2_counter
  8. add $s3, $zero, $zero # sum = 0
  9. addi $t4, 7
  10.  
  11. loop_start:
  12. sll $t2, $t0, 2 # $t2 = A1_counter * 4
  13. sll $t3, $t1, 2 # $t3 = A2_counter * 4
  14.  
  15. add $t2, $t2, $s1 # $t2 = &A1[0] + A1_counter * 4 i.e &A1[i]
  16. add $t3, $t3, $s2 # $t2 = &A2[0] + A2_counter * 4 i.e &A2[i[
  17.  
  18. # condition check
  19. lw $s0, 0($t2) # $s0 = A1[i]
  20. beq $s0, $zero, exit
  21.  
  22. # procedure call
  23. mov $a0, $s0
  24. jal is_even
  25.  
  26. if_number_is_even_start:
  27. # condition
  28. bne $v0, 1, if_number_is_even_end:
  29.  
  30. # true evaluation
  31. add $s3, $s3, $s0 # sum += A1[i]
  32. if_number_is_even_end:
  33.  
  34. if_number_ends_with_ones_start:
  35. # condition
  36. and $t5, $s0, $t4
  37. bne $t5, $t4 # jump if (A[i] & 7) != 7
  38.  
  39. # true evaluation
  40. sw $s0, 0($t3) # A2[j] = A1[i]
  41. addi $t1, $t1, 1 # ++j
  42. if_number_ends_with_ones_end:
  43.  
  44. addi $t0, $t0, 1 # ++i
  45. j loop_start
  46.  
  47. loop_end:
  48.  
  49.  
  50.  
  51. is_even:
  52. addi $t7, $zero, 2
  53. div $a0, $t0
  54. mfhi $t0
  55.  
  56. if_remainder_is_zero:
  57. #condition
  58. bne $t7, $zero, else
  59.  
  60. # return 1
  61. addi $v0, $zero, 1
  62. jr $ra
  63. else:
  64. # return 0
  65. addi $v0, $zero, $zero
  66. jr $ra
  67.  
  68.  
  69. exit:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement