Annotation of coherent/b/lib/libc/crt/i8086/ixcmp.s, revision 1.1.1.1

1.1       root        1: ////////
                      2: /
                      3: / Intel 8086 floating point.
                      4: / Double compare.
                      5: / SMALL model.
                      6: /
                      7: ////////
                      8: 
                      9:        .globl  ircmp
                     10:        .globl  ilcmp
                     11:        .globl  urcmp
                     12:        .globl  ulcmp
                     13: 
                     14: ////////
                     15: /
                     16: / ** ircmp -- double compare (rvalue)
                     17: / ** ilcmp -- double compare (lvalue)
                     18: /
                     19: / these two routines perform floating point compares. both the rvalue
                     20: / and the lvalue forms are provided for use by the compiler. ax  gets
                     21: / set to a completion code; an or ax,ax sets the flags so that a jump
                     22: / instruction may be generated.
                     23: /
                     24: / compiler calling sequences:
                     25: /      push    <right double argument>
                     26: /      push    <left  double argument>
                     27: /      call    ircmp
                     28: /      add     sp,16
                     29: /
                     30: /      mov     ax,offset <right double argument>
                     31: /      push    ax
                     32: /      push    <left  double argument>
                     33: /      call    ilcmp
                     34: /      add     sp,10
                     35: /
                     36: / outputs:
                     37: /      ax =-1 if l<r
                     38: /      ax = 0 if l=r
                     39: /      ax = 1 if l>r
                     40: /
                     41: / uses:
                     42: /      ax, bx, cx, dx
                     43: /
                     44: ////////
                     45: 
                     46: expon  =       0x7F80                  / DECVAX format exponent bits
                     47: 
                     48: l      =       8                       / left argument
                     49: r      =       16                      / right argument (rvalue)
                     50: rp     =       16                      / right argument (lvalue)
                     51: 
                     52: urcmp:
                     53: ircmp: push    si                      / standard
                     54:        push    di                      / c
                     55:        push    bp                      / function
                     56:        mov     bp,sp                   / linkage
                     57:        lea     di,r(bp)                / di=pointer to right op.
                     58:        jmp     L0                      / go to common code.
                     59: 
                     60: ulcmp:
                     61: ilcmp: push    si                      / standard
                     62:        push    di                      / c
                     63:        push    bp                      / function
                     64:        mov     bp,sp                   / linkage.
                     65:        mov     di,rp(bp)               / di=pointer to right op.
                     66: 
                     67: L0:    sub     ax,ax                   / default return equal.
                     68:        mov     bx,l+6(bp)              / bx=sign/exp word of left op.
                     69:        mov     cx,6(di)                / cx=sign/exp word of right op.
                     70:        test    bx,$expon               / check if left is zero.
                     71:        jnz     L1                      / left nonzero.
                     72:        test    cx,$expon               / check if right is zero.
                     73:        jz      L6                      / 0:0, return equal.
                     74:        orb     ch,ch                   / check sign of right.
                     75:        js      GT                      / 0:-, return greater.
                     76: LT:    dec     ax                      / 0:+, return less.
                     77:        jmp     L6                      / all done.
                     78: 
                     79: / Left is nonzero.
                     80: L1:    orb     bh,bh                   / check left sign.
                     81:        js      L3                      / jump if negative.
                     82:        test    cx,$expon               / check if right is zero.
                     83:        jnz     L2                      / jump if nonzero.
                     84: GT:    inc     ax                      / +:0, return greater.
                     85:        jmp     L6                      / all done.
                     86: 
                     87: / Left is positive, right is nonzero.
                     88: L2:    orb     ch,ch                   / check sign of right.
                     89:        jns     L4                      / jump if both positive.
                     90:        jmp     GT                      / +:-, return greater.
                     91: 
                     92: / Left is negative.
                     93: L3:    test    cx,$expon               / check if right is zero.
                     94:        jz      LT                      / -:0, return less.
                     95:        orb     ch,ch                   / check sign of right op.
                     96:        jns     LT                      / -:+, return less.
                     97: 
                     98: / Left and right both nonzero and both same sign.
                     99: L4:    add     di,$6                   / di=right op.
                    100:        lea     si,l+6(bp)              / si=left  op.
                    101:        mov     cx,$4                   / cx=count (4 words)
                    102:        std                             / decrement.
                    103:        repe                            / do the
                    104:        cmpsw                           / long compare.
                    105:        cld                             / reset the increment flag.
                    106:        je      L6                      / matches, return equal.
                    107:        inc     ax                      / ax=1, cf=untouched.
                    108:        jae     L5                      / jump if correct assumption.
                    109:        neg     ax                      / less.
                    110: 
                    111: L5:    orb     bh,bh                   / were operands less than zero.
                    112:        jns     L6                      / jump if not.
                    113:        neg     ax                      / yes, flip sense.
                    114: 
                    115: L6:    pop     bp                      / standard
                    116:        pop     di                      / c
                    117:        pop     si                      / function
                    118:        ret                             / return
                    119: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.