x86 provides powerful BCD adjustment instructions for packed and unpacked BCD.
If you add 7 ( 0111 ) + 6 ( 0110 ) in standard binary, the result is 13 ( 1101 ). In BCD, 1101 is an invalid representation (since valid digits only go up to 9, or 1001 ). bcd commands
mov a, #0x45 add a, #0x27 da a ; A = 0x72 x86 provides powerful BCD adjustment instructions for packed
bootrec /fixmbr bootrec /fixboot bootrec /rebuildbcd mov a, #0x45 add a, #0x27 da a
:
bcd_add_4digit: mov ax, dx ; low word? and ax, 0x00FF ; low byte of BCD1 mov cx, bx and cx, 0x00FF ; low byte of BCD2 add al, cl daa ; adjust low byte mov cl, al ; save low result mov al, ah adc al, ch daa ; adjust second byte mov ch, al ; save second byte
binary = (high_digit * 10) + low_digit