Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Jan Waclawek
04/02/13 13:02
Read: 933 times

#189610 - using DAA
Responding to: Muhammad Younas's previous message
While you can't use DAA after SUBB, the trick is to produce a "100-s" complement of the subtrahend, and then add that using ADD/DAA i.e. A-B -> A+(100-B). Another small trick involves carry and 99 rather than 100. As 99 is the highest BCD number, there is no risk of underflowing during the SUBB. The following snippet is stolen from BASIC52 and slightly adopted (I hope I did not spoil anything), subtracting two 8-digit numbers stored MSB-first:
        DSEG   AT  30h
X:      DS      4
Y:      DS      4

        MOV     X+0, #12h
        MOV     X+1, #34h
        MOV     X+2, #56h
        MOV     X+3, #78h
        MOV     Y+0, #98h
        MOV     Y+1, #76h
        MOV     Y+2, #54h
        MOV     Y+3, #32h

        MOV     R0, #Y+3
        MOV     R1, #X+3
        MOV     R7, #4
        SETB    C
        MOV     A,@R0
        MOV     R6,A
        CLR     A
        ADDC    A,#99H
        SUBB    A,@R1
        ADD     A,R6
        DA      A
        MOV     @R0,A
        DEC     R0
        DEC     R1
        DJNZ    R7,SUBLP


List of 2 messages in thread
decimal adjust after subtraction      Muhammad Younas      03/28/13 04:42      
   using DAA      Jan Waclawek      04/02/13 13:02      

Back to Subject List