]> git.sur5r.net Git - cc65/blob - libsrc/runtime/icmp.s
Made the code that logs indirect-goto referals be a little more efficient.
[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, tosicmp0
9         .importzp       sp, sreg
10
11
12 tosicmp0:
13         ldx     #$00
14
15 tosicmp:
16         sta     sreg
17         stx     sreg+1          ; Save ax
18
19         ldy     #$00
20         lda     (sp),y          ; Get low byte
21         tax
22         inc     sp              ; 5
23         bne     @L1             ; 3
24         inc     sp+1            ; (5)
25 @L1:
26         lda     (sp),y          ; Get high byte
27         inc     sp              ; 5
28         bne     @L2             ; 3
29         inc     sp+1            ; (5)
30
31 ; Do the compare.
32
33 @L2:    sec
34         sbc     sreg+1          ; Compare high byte
35         bne     @L4
36         cpx     sreg            ; Compare low byte
37         beq     @L3
38         adc     #$FF            ; If the C flag is set then clear the N flag
39         ora     #$01            ; else set the N flag
40 @L3:    rts
41
42 @L4:    bvc     @L3
43         eor     #$FF            ; Fix the N flag if overflow
44         ora     #$01            ; Clear the Z flag
45         rts
46
47