문제

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
도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top