Advertisement
Guest User

Untitled

a guest
Jan 13th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. ; ***** SFLOAT32 MULTIPLY ************************************************
  2. ; Function: SFLOAT32Mul
  3. ; Input: SFLOAT32 |r23|r22|r21|r20|, SFLOAT32 |r19|r18|r17|r16|
  4. ; Output: SFLOAT32 |r23|r22|r21|r20|
  5. ; Destroys: SREG, r0, r1, r2, r18, r19, r24 ... r29
  6. ; Calls: None
  7. ; Cycles: 81 ... 87
  8. ; Bytes: 136
  9. ; Description: Returns product of arguments with last bit floored.
  10. ; Note that overflows/underflows are not handled!
  11. SFLOAT32Mul:
  12. clr r2 ; clear r2 for calculating carries later
  13.  
  14. clt ; clear test bit for storing sign later
  15. eor r23, r19 ; xor leading bytes to xor sign bits
  16. sbrc r23, 7 ; skip if sign bit is cleared
  17. set ; store sign bit in test bit
  18. eor r23, r19 ; xor leading bytes to restore argument
  19.  
  20. lsl r22 ; shift the lsb of exponent into carry
  21. rol r23 ; rotate carry into leading byte s.t. it is the entire exponent
  22. sec ; set carry to rotate into 2nd byte
  23. ror r22 ; rotate carry s.t. msb of mantissa is a '1'
  24.  
  25. lsl r18 ; repeat above for 2nd argument
  26. rol r19 ; ^
  27. sec ; ^
  28. ror r18 ; ^
  29.  
  30. mul r22, r18 ; A3 * B3
  31. movw r28, r0 ;
  32.  
  33. mul r21, r17 ; A2 * B2
  34. movw r26, r0 ;
  35.  
  36. mul r20, r16 ; A1 * B1
  37. movw r24, r0 ;
  38.  
  39. mul r21, r16 ; A2 * B1
  40. add r25, r0 ;
  41. adc r26, r1 ;
  42. adc r27, r2 ;
  43. adc r28, r2 ;
  44. adc r29, r2 ;
  45.  
  46. mul r20, r17 ; A1 * B2
  47. add r25, r0 ;
  48. adc r26, r1 ;
  49. adc r27, r2 ;
  50. adc r28, r2 ;
  51. adc r29, r2 ;
  52.  
  53. mul r22, r16 ; A3 * B1
  54. add r26, r0 ;
  55. adc r27, r1 ;
  56. adc r28, r2 ;
  57. adc r29, r2 ;
  58.  
  59. mul r20, r18 ; A1 * B3
  60. add r26, r0 ;
  61. adc r27, r1 ;
  62. adc r28, r2 ;
  63. adc r29, r2 ;
  64.  
  65. mul r22, r17 ; A3 * B2
  66. add r27, r0 ;
  67. adc r28, r1 ;
  68. adc r29, r2 ;
  69.  
  70. mul r21, r18 ; A2 * B3
  71. add r27, r0 ;
  72. adc r28, r1 ;
  73. adc r29, r2 ;
  74.  
  75. add r23, r19 ; add exponents together
  76. subi r23, 125 ; subtract the offset of 127 minus upto 2 shifts to normalize
  77.  
  78. SFLOAT32Mul_Normalize:
  79. dec r23 ; decrement exponent due to shift
  80. lsl r26 ; shift unnormalized mantissa left
  81. rol r27 ; ^
  82. rol r28 ; ^
  83. rol r29 ; ^
  84. brcc SFLOAT32Mul_Normalize ; shift until leading '1' of mantissa is removed
  85.  
  86. mov r22, r29 ; move unformated mantissa to result
  87. mov r21, r28 ; ^
  88. mov r20, r27 ; ^
  89.  
  90. brts SFLOAT32Mul_Sign ; branch if the sign bit must be set
  91. clc ; otherwise clear carry
  92.  
  93. SFLOAT32Mul_Sign:
  94. ror r23 ; rotate carry into msb and format mantissa
  95. ror r22 ; ^
  96. ror r21 ; ^
  97. ror r20 ; ^
  98.  
  99. ret ; return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement