]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lcmp.s
Merge pull request #609 from polluks/master
[cc65] / libsrc / runtime / lcmp.s
1 ;
2 ; Piotr Fusik, 15.04.2002
3 ; originally by Ullrich von Bassewitz
4 ;
5 ; Long int compare function - used by the compare operators
6 ;
7
8         .export         toslcmp
9         .import         incsp4
10         .importzp       sp, sreg, ptr1
11
12
13 toslcmp:
14         sta     ptr1
15         stx     ptr1+1          ; EAX now in sreg:ptr1
16
17         ldy     #$03
18         lda     (sp),y
19         sec
20         sbc     sreg+1
21         bne     L4
22
23         dey
24         lda     (sp),y
25         cmp     sreg
26         bne     L1
27
28         dey
29         lda     (sp),y
30         cmp     ptr1+1
31         bne     L1
32
33         dey
34         lda     (sp),y
35         cmp     ptr1
36
37 L1:     php                     ; Save flags
38         jsr     incsp4          ; Drop TOS
39         plp                     ; Restore the flags
40         beq     L2
41         bcs     L3
42         lda     #$FF            ; Set the N flag
43 L2:     rts
44
45 L3:     lda     #$01            ; Clear the N flag
46         rts
47
48 L4:     bvc     L5
49         eor     #$FF            ; Fix the N flag if overflow
50         ora     #$01            ; Clear the Z flag
51 L5:     php                     ; Save flags
52         jsr     incsp4          ; Drop TOS
53         plp                     ; Restore flags
54         rts
55
56