rmi4.s 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. .sect .text; .sect .rom; .sect .data; .sect .bss
  2. .sect .text
  3. .define .rmi4
  4. yl=6
  5. yh=8
  6. xl=10
  7. xh=12
  8. .rmi4:
  9. push si
  10. push di
  11. mov si,sp ! copy of sp
  12. mov bx,yl(si)
  13. mov ax,yh(si)
  14. cwd
  15. cmp dx,ax
  16. jne 7f
  17. and dx,dx
  18. jge 1f
  19. neg bx
  20. je 7f
  21. 1:
  22. xor dx,dx
  23. mov cx,xl(si)
  24. mov ax,xh(si)
  25. and ax,ax
  26. jge 2f
  27. neg ax
  28. neg cx
  29. sbb ax,dx
  30. 2:
  31. div bx
  32. xchg ax,cx
  33. div bx ! dx= result(low), 0=result(high)
  34. xor bx,bx
  35. 9:
  36. cmp xh(si),0
  37. jge 1f
  38. neg bx
  39. neg dx
  40. sbb bx,0
  41. 1:
  42. ! bx is high order result
  43. ! dx is low order result
  44. mov ax,dx
  45. mov dx,bx ! result in ax/dx
  46. pop di
  47. pop si
  48. ret 8
  49. 7:
  50. mov di,ax
  51. xor bx,bx
  52. and di,di
  53. jge 1f
  54. neg di
  55. neg yl(si)
  56. sbb di,bx
  57. 1:
  58. mov ax,xl(si)
  59. mov dx,xh(si)
  60. and dx,dx
  61. jge 1f
  62. neg dx
  63. neg ax
  64. sbb dx,bx
  65. 1:
  66. mov cx,16
  67. 1:
  68. shl ax,1
  69. rcl dx,1
  70. rcl bx,1
  71. cmp di,bx
  72. ja 3f
  73. jb 2f
  74. cmp yl(si),dx
  75. jbe 2f
  76. 3:
  77. loop 1b
  78. ! dx=result(low), bx=result(high)
  79. jmp 9b
  80. 2:
  81. sub dx,yl(si)
  82. sbb bx,di
  83. inc ax
  84. loop 1b
  85. 1:
  86. ! dx=result(low), bx=result(high)
  87. jmp 9b