Guest User

Untitled

a guest
Oct 15th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. global Mul
  2. global Div
  3.  
  4. ; input: [esp+4] m
  5. ; [esp+8] n
  6. ; return: eax low word of product
  7. ; edx high word of product
  8. Mul:
  9. push esi
  10. push edi
  11.  
  12. ; ecx n
  13. mov ecx,[esp+12]
  14. ; esi,edi m
  15. mov edi,[esp+16]
  16. xor esi,esi
  17. ; edx,eax p
  18. xor eax,eax
  19. xor edx,edx
  20.  
  21. and ecx,ecx
  22. jz .done
  23. .loop:
  24. shr ecx,1
  25. jnc .zerobit
  26. add eax,edi
  27. adc edx,esi
  28. .zerobit:
  29. shl edi,1
  30. rcl esi,1
  31. and ecx,ecx
  32. jnz .loop
  33.  
  34. .done:
  35. pop edi
  36. pop esi
  37. ret
  38.  
  39.  
  40. ; quotient in eax
  41. ; remainder in edx
  42.  
  43. Div:
  44. push ebx
  45. push esi
  46.  
  47. xor eax,eax ; q
  48. mov ebx,[esp+16] ; d
  49. xor edx,edx ; r
  50. mov esi,[esp+12] ; n
  51.  
  52. mov ecx,32 ; i
  53. .loop:
  54. shl eax,1
  55. shl edx,1
  56. shl esi,1
  57. adc edx,0
  58. cmp edx, ebx
  59. jl .ge
  60. sub edx, ebx
  61. add eax,1
  62. .ge:
  63. dec ecx
  64. jnz .loop
  65.  
  66. .done:
  67. pop esi
  68. pop ebx
  69. ret
  70.  
  71. ; vim:ft=nasm
Add Comment
Please, Sign In to add comment