0

I am trying to do Addition on two register. It show result Correctly until the result of addition is less than 20. As the result goes above 20. Program is displaying garbage values:

Here is the code

mov ax, 10
mov bx, 9

add ax, bx
aaa
mov bx, ax

add bl, 48
add bh, 48

mov ah, 02
mov dl, bh
int 21h


mov ah, 02
mov dl, bl
int 21h

What I am doing wrong? :' (

  • 1
    What inputs are you using for outputs higher of 20 or higher? Like `mov ax, 0x0102` for unpacked-BCD `12` (AH=1, AL=2) and `mov bx, 0x0203` for unpacked-BCD `23`? Because inputs like that are what `aaa` is designed to clean up after; look at the docs for how it works, checking if AL & 0xF > 9 and if so, incrementing AH and wrapping AL. https://www.felixcloutier.com/x86/aaa . Your question shows working code, not quite a [mcve]. Although we can already see an "abuse" of the BCD instruction `aaa`, using it after adding `0x000a` to something, and AL=10 isn't a single decimal digit. – Peter Cordes Jan 10 '23 at 12:15
  • 1
    If unpacked-BCD isn't the integer format you wanted to be using, then use normal `add` on binary integers and use division by 10 to get the decimal digits out: [Displaying numbers with DOS](https://stackoverflow.com/q/45904075) – Peter Cordes Jan 10 '23 at 12:16

0 Answers0