Advertisement
Duoshot

Untitled

Oct 10th, 2013
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. fmt: .asciz "Product = %x%x\n"
  2. .align 4
  3. .global main
  4.  
  5. main:
  6.  
  7. save %sp, -96, %sp
  8.  
  9. !set 0x72e8b8c, %l2 !multiplier
  10. !set 0x4ee67b7, %l0 !multiplicand
  11.  
  12. !set 0x04ee67b7, %l0 !multiplicand
  13. !set 0xf8d17474, %l2 !multiplier
  14.  
  15. set 0xfb119849, %l0 !multiplicand
  16. set 0xf8d17474, %l2 !multiplier
  17.  
  18.  
  19. set 0x0, %l1 !product
  20. clr %l4 !clear register
  21. mov 0, %l3 !counter
  22. set 0x8, %g3 !bitmask
  23. clr %l6
  24.  
  25. negTest:
  26.  
  27. srl %l2, 31, %g1 !get the MSB of multiplier
  28.  
  29. andcc %g1, 1, %g0 !test if multiplier is negative
  30. be loop !go to loop if
  31. nop
  32.  
  33. mov 1, %l4 !set negative flag to true
  34. nop
  35.  
  36. loop:
  37.  
  38. andcc %l2, 1, %g0 !test if LSB is 1.
  39. be shift !go to shift if LSB isn't 1.
  40. nop
  41. add %l1, %l0, %l1 !add multiplicand and product
  42. nop
  43.  
  44. shift:
  45. and %l1, 0x1, %l6
  46. sll %l6, 31, %l6
  47. srl %l2, 1, %l2
  48. sra %l1, 1, %l1
  49. or %l2, %l6, %l2
  50.  
  51. add %l3, 1, %l3
  52. subcc %l3, 32, %g0
  53. bl loop
  54. cmp %l4, 0
  55. be end
  56. nop
  57. sub %l1, %l0, %l1
  58. nop
  59.  
  60.  
  61.  
  62. end: set fmt, %o0
  63. mov %l1, %o1
  64. mov %l2, %o2
  65. call printf
  66.  
  67.  
  68. mov 1, %g1
  69. ta 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement