I don't know why I can't get the desired output for division (rediv specifically). For multiplication, I got my desired output. Fortunately, I got the desired output for recar/carry. Man, it is frustrating because I have no idea why I'm not getting it right with rediv. Below is the sample code. Thanks in advance.
.model small
.stack 100h
.data
in1 db 'Enter number 1: $'
in3 db 0Ah,0Dh, 'Enter number 1 again (For division operation): $'
in2 db 0Ah,0Dh, 'Enter number 2: $'
temp1 db ?
temp2 db ?
temp3 dw ?
remul db ?
rediv db ?
recar db ?
output1 db 0Ah,0Dh, 'The multiplication result is : $'
output2 db 0Ah,0Dh, 'The division result is : $'
output3 db 0Ah,0Dh, 'The carry is : $'
.code
;Input
mov ax,@data
mov ds,ax
lea dx,in1
mov ah,9h
int 21h
mov ah,1
int 21h
mov temp1,al
lea dx,in3
mov ah,9h
int 21h
mov ah,1
int 21h
mov temp3,ax
lea dx,in2
mov ah,9h
int 21h
mov ah,1
int 21h
mov temp2,al
;Multplication
mov al,temp1
sub al,48
mov bl,temp2
sub bl,48
mul bl
add al,48
mov remul,al
lea dx,output1
mov ah,9h
int 21h
mov ah,2
mov dl,remul
int 21h
;Division
mov ax,temp3
sub ax,48
mov bl,temp2
sub bl,48
div bl
add al,48
mov rediv,al
add ah,48
mov recar,ah
lea dx,output2
mov ah,9h
int 21h
mov ah,2
mov dl,rediv
int 21h
lea dx,output3
mov ah,9h
int 21h
mov ah,2
mov dl,recar
int 21h
mov ah,4ch
int 21h
end
CodePudding user response:
mov ah,1 int 21h mov temp3,ax <<<< This is the problem!
mov ax,temp3 sub ax,48 mov bl,temp2 sub bl,48 div bl
Your division is using an AX
register that is too big!
Returning from the DOS.GetCharacter call, the AH
register is still equal to 1. You need a 0 there.
Quick fix:
mov ah, 0
div bl
A better fix would be to define your temp3 variable a byte, or even better, don't use a third variable as it is essentially the same as the temp1 variable.