cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

abs.s (670B)


      1        .module abs
      2
      3        .area   _HOME
      4
      5; int abs(int)
      6_abs::
      7        lda     HL, 3(SP)   ; 3
      8        ld      A,(HL-)     ; 2 Load high byte.
      9        ld      D,A         ; 1
     10        ld      E,(HL)      ; 2 Load low byte
     11        add     A,A         ; 1 Sign check.
     12        ret     nc          ; 5/2 Return if positive.
     13        xor     A           ; 1 A=0.
     14        sub     E           ; 1 Calculate 0-(low byte).
     15        ld      E,A         ; 1
     16        ld      A,#0        ; 2 A=0. Can't use xor A because carry flag needs to be preserved. 
     17        sbc     D           ; 1 Calculate 0-(high byte)-carry.
     18        ld      D,A         ; 1
     19        ret                 ; 4