Advertisement
foreverfugazi

DIV TEST

Oct 3rd, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. # storing variables in memory
  2. .data
  3. A: .word 3
  4. B: .word 26
  5.  
  6. .text
  7. la x3, A
  8. la x4, B
  9. lw x5, 0(x3) # A
  10. lw a0, 0(x4) # B
  11. addi x1, x0, 0 # Initialize result to 0
  12.  
  13. loop:
  14. blt a0, x5, check # Branch when B < A
  15. sub a0, a0, x5 # Else B = B - A
  16. beq x0, x0, loop # Unconditional jump
  17.  
  18. check:
  19. bne a0, x0, exit
  20. addi x1, x0, 1 # If remainder = 0 then divisible
  21. exit:
  22. nop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement