foreverfugazi

code checking

Sep 12th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. .data
  2. cod: .word 0x05 # store input in memory
  3.  
  4. .text
  5. la x10, cod # load address
  6. lw x2, 0(x10) # load data from address
  7. li x7, 5 # loop counter
  8. li x4, 1 # to go through bits one by one
  9. li x8, 2 # desired result
  10. li x1, 0 # counts number of high bits
  11. andi x3, x2, 0xffffffe0 # mask lower 5 bits
  12. bne x3, x0, notacode # if any other bit is high, return 0
  13. back:
  14. and x5, x2, x4 # mask
  15. beq x5, x0, next # check if high
  16. addi x1, x1, 1 # increment 1 if high
  17. next:
  18. slli x4, x4, 1 # shift mask to next position
  19. addi x7, x7, -1 # update loop counter
  20. bne x7, x0, back
  21. bne x1, x8, notacode # check desired result
  22. addi x11, x0, 0xff # if satisfied store FF
  23. store:
  24. sb x11, 4(x10) # storing happens here
  25. j exit
  26. notacode:
  27. add x11, x0, x0 # else store 0
  28. beq x0, x0, store
  29. exit:
  30. nop # end of program
Add Comment
Please, Sign In to add comment