]> git.sur5r.net Git - cc65/blob - libsrc/runtime/icmp.s
Added an IRQ vector
[cc65] / libsrc / runtime / icmp.s
1 ;
2 ; Piotr Fusik, 15.04.2002
3 ; originally by Ullrich von Bassewitz
4 ;
5 ; Integer compare function - used by the compare operators
6 ;
7
8         .export         tosicmp
9         .importzp       sp, sreg
10
11
12 tosicmp:
13         sta     sreg
14         stx     sreg+1          ; Save ax
15
16         ldy     #$00
17         lda     (sp),y          ; Get low byte
18         tax
19         inc     sp              ; 5
20         bne     @L1             ; 3
21         inc     sp+1            ; (5)
22 @L1:
23         lda     (sp),y          ; Get high byte
24         inc     sp              ; 5
25         bne     @L2             ; 3
26         inc     sp+1            ; (5)
27
28 ; Do the compare.
29
30 @L2:    sec
31         sbc     sreg+1          ; Compare high byte
32         bne     @L4
33         cpx     sreg            ; Compare low byte
34         beq     @L3
35         adc     #$FF            ; If the C flag is set then clear the N flag
36         ora     #$01            ; else set the N flag
37 @L3:    rts
38
39 @L4:    bvc     @L3
40         eor     #$FF            ; Fix the N flag if overflow
41         ora     #$01            ; Clear the Z flag
42         rts
43
44