Question

The output of the below assembly code is expected to be 6 but it is coming as 3. What's wrong?

data_seg    segment 
msg1 db "hi",10,13,"$"
msg3 db 26
num db 10
data_seg    ends
code_seg    segment
assume  cs:code_seg, ds:data_seg
start:
        mov ax,data_seg                 ;init
        mov ds,ax

    loop1:
        mov ah,0
        mov al,msg3
        div num
        mov ah,02
        int 21h
    term:   
        mov ah,4ch          ;termination code                       
        mov al,0
        int 21h
code_seg    ends
end start
Was it helpful?

Solution

From the documentation:

Unsigned binary division of accumulator by source. If the source divisor is a byte value then AX is divided by src and the quotient is placed in AL and the remainder in AH. If source operand is a word value, then DX:AX is divided by src and the quotient is stored in AX and the remainder in DX.

OTHER TIPS

DOS function AH=02h expects character code in DL register.
Your division operation is word(AX)/byte(10) -> quot(AL)+res(AH) and doesn't change DL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top