cmi4.s 802 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. .define Cmi4
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine compares on fourbyte integers.
  8. ! If T is pushed first and than S, the routine will return:
  9. ! -1 if S < T,
  10. ! 0 if S = T,
  11. ! 1 if S > T.
  12. Cmi4:
  13. jsr Sbi4 ! subtract operands (T - S)
  14. jsr Pop ! get result (lowbyte, lowbyte+1)
  15. stx ARTH ! store lowbyte
  16. sta ARTH+1 ! store lowbyte+1
  17. jsr Pop ! get result (lowbyte+2, lowbyte+3)
  18. tay ! test lowbyte+3
  19. bpl 1f ! S >= T
  20. lda #0x0FF ! S < T
  21. tax ! AX becomes -1
  22. rts
  23. 1: cmp #0 ! test lowbyte+3 on zero
  24. bne 2f
  25. cpx #0 ! test lowbyte+2 on zero
  26. bne 2f
  27. lda #0
  28. cmp ARTH+1 ! test lowbyte+1 on zero
  29. bne 2f
  30. cmp ARTH ! test lowbyte on zero
  31. bne 2f
  32. lda #0 ! S = T
  33. tax ! AX becomes 0
  34. rts
  35. 2: lda #0 ! S > T
  36. ldx #1 ! AX becomes 1
  37. rts