[英]How to divide two digit number
我需要显示问题,用户将回答Y或N。我总共有5个问题,其中1个问题有20分。 我将需要5 * 20 = 100。 当用户回答Y时, countY db 0
将增加20
我已经成功计算出标记,但是如何显示标记是一个两位数的数字(例如80),也可能是一个3位的数字(例如100)。
Q1:
mov ah, 09h
lea dx, msgq1
int 21h
mov ah, 01h
int 21h
mov myInput, al
cmp myInput, 59h
JE I1
jmp Q2
I1:
mov dl, countY
add dl,20
mov countY, dl
;calculation
Cal:
mov ah,02h
mov dl, countY
add dl, 30h ; display countY=80;
mov countY, dl
int 21h
;NOT WORKING, ERROR CODE
mov bl,10
mov al, countY
cbw
div bl
mov q, al
mov r, ah
mov ah, 02h
mov q, al
int 21h
cal: mov ah,02h mov dl, countY add dl, 30h ; display countY=80; mov countY, dl int 21h ;NOT WORKING, ERROR CODE mov bl,10 mov al, countY cbw div bl
进行这种划分时,您的方法是正确的,但很遗憾,上面的几行破坏了countY中的值。
从除法器中获得商和余数后,需要使用DOS显示它们。 首先是商,然后是余数。 但是您一定不要忘记将每个字符加30h来将它们变成字符。
cal:
mov bl,10
mov al, countY ;Values are {0,20,40,60,80}
cbw ;Prepare for division of AX/BL
div bl ; -> AL=quotient AH=remainder
mov dx, ax ;Conveniently moving both to DX
add dx, 3030h ;Adding 30h to each in a single instruction
mov ah, 02h
int 21h ;Display the tenths
mov dl, dh
mov ah, 02h
int 21h ;Display the ones
唯一缺少的是分数可能精确为100,因此需要3位数字的情况。
只需检测它,显示前导“ 1”,从商中减去10,然后像以前一样继续:
cal:
mov bl,10
mov al, countY ;Values are {0,20,40,60,80,100}
mov ah, 0 ;Prepare for division of AX/BL
div bl ; -> AL=quotient AH=remainder
cmp al, 10
jl Skip
push ax ;Save AX because the DOS call destroys it's value
mov dl, "1"
mov ah, 02h
int 21h ;Display the hundreds
pop ax ;Restore AX
sub al, 10
Skip:
mov dx, ax ;Conveniently moving both to DX
add dx, 3030h ;Adding 30h to each in a single instruction
mov ah, 02h
int 21h ;Display the tenths
mov dl, dh
mov ah, 02h
int 21h ;Display the ones
通过将cbw
更改为mov ah,0
,此版本的代码可以显示0到199之间的所有数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.