Reputation: 2429
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
Upvotes: 0
Views: 4636
Reputation: 500853
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.
Upvotes: 6
Reputation: 23767
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
.
Upvotes: 1