??? 04/02/13 19:02 Read: times |
#189610 - using DAA Responding to: ???'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 CSEG 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 SUBLP: 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 EEE: SJMP EEE END |
Topic | Author | Date |
decimal adjust after subtraction | 01/01/70 00:00 | |
using DAA | 01/01/70 00:00 |