Search code examples
assemblymasmx86-16

wrong output on subtraction 35-39=6?


Can any one explain why this code giving me wrong o/p

data segment
num1 db 35h
num2 db 39h
result db 00h
data ends
code segment
assume cs: code, ds: data
start:
            mov ax,data
            mov ds ,ax
            mov ax,0000h
            mov al,num1
            sub al,num2
            aas
            mov result,al
            int 03h
            code ends
end start 
end

OUTPUT:

-g

AX=FF06  BX=0000  CX=0024  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000
DS=146C  ES=145C  SS=146C  CS=146D  IP=0013   NV UP EI PL NZ AC PO CY
146D:0013 CC            INT     3
-d ds:0l10
146C:0000  35 39 06 00 00 00 00 00-00 00 00 00 00 00 00 00   59..............
-

i'm expecting AX to be FF04.

I'm just started learning it so use simple explanation if possible.


Solution

  • You are using the unpacked instruction aas which gives the result -4 in unpacked BCD 06, but you are performing packed BCD and need the packed variant das to get the correct answer 96.