dvi4.s 1.2 KB

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