l_long_cmp_new.asm
bitfixer_bitfixer/dg/z88dk/libsrc/z80_crt0s/crt0_long/l_long_cmp_new.asm
;
;
;       Small C+ C Compiler
;
;       Long Support Functions
;
;       26/2/99 djm

;
;       I've realised that all the old long comparision functions were
;       (to be polite) fubarred, so I'm endeavouring to rewrite
;       the core so that we get some decent answers out - this is
;       helped no end by having a l_long_sub function which works
;       the right way round!
;
;       Anyway, on with the show; this is the generic compare routine
;       used for all long comparisons.

;       Entry: dehl=secondary
;              onstack (under two return addresses) = primary
;
;
;       Exit:     z=number is zero
;              (nz)=number is non-zero 
;                 c=number is negative
;                nc=number is positive


                XLIB    l_long_cmp


.l_long_cmp
        pop     bc      ;return address from this function
                        ;this leaves return address to real program
                        ;and the primary on the stack

; Code cut from l_long_sub here
        exx             ;2nd
        pop     bc
        pop     hl
        pop     de
        push    bc      ;return address to program
        ld      a,l
        exx
        push    bc      ;return address from function
        sub     l
        ld      l,a
        exx             ;1st
        ld      a,h
        exx             ;2nd
        sbc     a,h
        ld      h,a
        exx             ;1st
        ld      a,e
        exx             ;2nd
        sbc     a,e
        ld      e,a     
        exx             ;1st
        ld      a,d
        exx             ;2nd
        sbc     a,d
        ld      d,a

; ATP we have done the comparision and are left with dehl = result of
; primary - secondary

        bit     7.d
        jr      z,l_long_cmp1
; Negative numbers
        ld      a,h
        or      l
        or      d
        or      e
        ld      hl,1    ; Saves some mem in comparison functions
        scf
        ret

; Number is positive
.l_long_cmp1
        ld      a,h
        or      l
        or      d
        or      e
        scf             ; Could this be replaced by and a?
        ccf
        ld      hl,1    ; Saves some mem in comparision unfunctions
        ret



