[英]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.