dvu4.s 737 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. .sect .text; .sect .rom; .sect .data; .sect .bss
  2. .define .dvu4
  3. yl=6
  4. yh=8
  5. xl=10
  6. xh=12
  7. .sect .text
  8. .dvu4:
  9. push si
  10. push di
  11. mov si,sp ! copy of sp
  12. mov bx,yl(si)
  13. mov ax,yh(si)
  14. or ax,ax
  15. jne 7f
  16. xor dx,dx
  17. mov cx,xl(si)
  18. mov ax,xh(si)
  19. div bx
  20. xchg ax,cx
  21. div bx
  22. 9:
  23. ! cx is high order result
  24. ! ax is low order result
  25. mov dx,cx
  26. pop di
  27. pop si
  28. ret 8 ! result in ax/dx
  29. 7:
  30. mov di,ax
  31. xor bx,bx
  32. mov ax,xl(si)
  33. mov dx,xh(si)
  34. mov cx,16
  35. 1:
  36. shl ax,1
  37. rcl dx,1
  38. rcl bx,1
  39. cmp di,bx
  40. ja 3f
  41. jb 2f
  42. cmp yl(si),dx
  43. jbe 2f
  44. 3:
  45. loop 1b
  46. jmp 9b
  47. 2:
  48. sub dx,yl(si)
  49. sbb bx,di
  50. inc ax
  51. loop 1b
  52. jmp 9b