cmi4.s 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. .define .cmi4
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! Compare 32 bits integers
  8. ! Expects: operands on stack
  9. ! a-register = 1 for signed integers
  10. ! a-register = 0 for unsigned integers
  11. ! Yields in de-registers: -1 if second operand < first operand
  12. ! 0 if second operand = first operand
  13. ! 1 if second operand > first operand
  14. .cmi4: pop h
  15. shld .retadr
  16. mov h,b
  17. mov l,c
  18. shld .bcreg
  19. lxi b,4
  20. lxi h,0
  21. dad sp
  22. dad b
  23. dcx h
  24. mov d,h
  25. mov e,l !now de points to the first operand
  26. dad b !and hl to the second
  27. ora a !is it a cmi or cmu?
  28. jz 1f
  29. !for cmi only:
  30. mov a,m
  31. ral
  32. jnc 2f
  33. ldax d !second operand is negative
  34. ral
  35. jc 1f !jump if both operands are negative
  36. lxi d,-1 !second operand is smaller
  37. jmp 4f
  38. 2: ldax d !second operand is positive
  39. ral
  40. jnc 1f !jump if both operand are positive
  41. lxi d,1 !second operand is larger
  42. jmp 4f
  43. !cmi and cmu rejoin here
  44. 1: ldax d
  45. cmp m
  46. jz 3f
  47. jnc 2f
  48. lxi d,1 !second operand is larger
  49. jmp 4f
  50. 2: lxi d,-1 !second operand is smaller
  51. jmp 4f
  52. 3: dcx d
  53. dcx h
  54. dcr c
  55. jnz 1b
  56. lxi d,0 !operands are equal
  57. 4: lxi h,8
  58. dad sp
  59. sphl
  60. lhld .bcreg
  61. mov b,h
  62. mov c,l
  63. lhld .retadr
  64. pchl