test_fastmultiply.S 703 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. .text
  2. .align 2
  3. .globl _start
  4. _start:
  5. addi a0, x0, 1123
  6. addi a1, x0, 5
  7. nop
  8. nop
  9. nop
  10. jal ra, fast_multiply
  11. nop
  12. nop
  13. nop
  14. loop:
  15. jal x0, loop
  16. nop
  17. nop
  18. nop
  19. fast_multiply:
  20. add t0, zero, zero # to keep track of result
  21. next_digit:
  22. andi t1, a1, 1 # is rightmost bit 1?
  23. srai a1, a1, 1
  24. nop
  25. nop
  26. beq t1, zero, skip # if right most bit 0, don't add
  27. nop
  28. nop
  29. nop
  30. add t0, t0, a0
  31. skip:
  32. slli a0, a0, 1 # double first argument
  33. bne a1, zero, next_digit
  34. nop
  35. nop
  36. nop
  37. add a0, zero, t0 # move accum result to a0
  38. jalr x0, ra, 0
  39. nop
  40. nop
  41. nop
  42. .end _start
  43. .size _start, .-_start