如何将此代码修复到该错误是商和剩余的答案?
在记事本++中使用TASM/TLINK/DOSBOX
WANT:如何将2位数字划分为2位数字,以及何时商或剩余答案是否也是2位数字?还有什么逻辑是什么?
我的流量是:我的流量是第一个我取了第一个数字或股利的第一个数字,然后我乘以10,然后将其添加到第二个数字中,与第二个数字或分数相同,以便它是2位数字在登记册中,我将把它们划分。
我在记事本++中的代码:
.model small
.stack 100h
.data
d0 db 0dh,0ah,"Base 03$"
d1 db 0dh,0ah,"Enter Dividend : $" ;string
d2 db 0dh,0ah,"Enter Divisor : $"
d3 db 0dh,0ah,"Display Quotient : $"
d4 db 0dh,0ah,"Display Remainder : $"
.code
main proc ;main program here
mov ax,@data ;initialize ds
mov ds,ax
Div1:
mov ah,09h
lea dx,d0
int 21h
lea dx, d1
int 21h
mov ah,01h
int 21h ;1st Digit
mov ch,al
mov ah,01h
int 21h ;2nd Digit
mov cl,al
or cx,3030h
mov al,ch
mov bl,10h
mul bl ;02*10 = 20
mov bh,al
add bh,cl ;dividend
Div2:
mov ah,09h
lea dx, d2
int 21h
mov ah,01h
int 21h ;1st Digit
mov ch,al
mov ah,01h
int 21h ;2nd Digit
mov cl,al
or cx,3030h
mov al,ch
mul bl
mov dh,al
add dh,cl ;divisor
mov ah,00h
mov al,bh
aad
div dh
mov cx,ax
or cx,3030h
mov ah,09h
lea dx, d3
int 21h
mov ah,02h
mov dl,cl
int 21h
mov ah,09h
lea dx, d4
int 21h
mov ah,02h
mov dl,ch
int 21h
mov ah,4Ch ;end here
int 21h
main endp
end main
output:
想要输出:
Enter Dividend : 22
Enter Divisor : 02
Display Quotient : 02
Display Remainder : 00
proj
Enter Dividend : 21
Enter Divisor : 02
Display Quotient : 10
Display Remainder : 01
proj
Enter Dividend : 21
Enter Divisor : 11
Display Quotient : 01
Display Remainder : 10
就像此计算一样,但是我唯一需要的是商和剩余。
using tasm/tlink/dosbox in notepad++
want: how do i fix 2 digit divide to 2 digits and when if the quotient or remainder answer is also 2 digits? and also what is the possible logic?
my flow is: the flow I made was first I took the first digit of the first number or dividend then I multiplied by 10 to be and I added to the second digit the same as the second number or divisor so that it would be 2 digits in the register after that I'll divide them both.
My Code in notepad++:
.model small
.stack 100h
.data
d0 db 0dh,0ah,"Base 03quot;
d1 db 0dh,0ah,"Enter Dividend : quot; ;string
d2 db 0dh,0ah,"Enter Divisor : quot;
d3 db 0dh,0ah,"Display Quotient : quot;
d4 db 0dh,0ah,"Display Remainder : quot;
.code
main proc ;main program here
mov ax,@data ;initialize ds
mov ds,ax
Div1:
mov ah,09h
lea dx,d0
int 21h
lea dx, d1
int 21h
mov ah,01h
int 21h ;1st Digit
mov ch,al
mov ah,01h
int 21h ;2nd Digit
mov cl,al
or cx,3030h
mov al,ch
mov bl,10h
mul bl ;02*10 = 20
mov bh,al
add bh,cl ;dividend
Div2:
mov ah,09h
lea dx, d2
int 21h
mov ah,01h
int 21h ;1st Digit
mov ch,al
mov ah,01h
int 21h ;2nd Digit
mov cl,al
or cx,3030h
mov al,ch
mul bl
mov dh,al
add dh,cl ;divisor
mov ah,00h
mov al,bh
aad
div dh
mov cx,ax
or cx,3030h
mov ah,09h
lea dx, d3
int 21h
mov ah,02h
mov dl,cl
int 21h
mov ah,09h
lea dx, d4
int 21h
mov ah,02h
mov dl,ch
int 21h
mov ah,4Ch ;end here
int 21h
main endp
end main
Output:
Want Output:
Enter Dividend : 22
Enter Divisor : 02
Display Quotient : 02
Display Remainder : 00
proj
Enter Dividend : 21
Enter Divisor : 02
Display Quotient : 10
Display Remainder : 01
proj
Enter Dividend : 21
Enter Divisor : 11
Display Quotient : 01
Display Remainder : 10
like this calculation but the only i need is the quotient and remainder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定“想要输出”?
或cx,3030h
对您的代码没有任何作用,因为这些位已经设置为48到50。 ,3030h 。接下来,您使用10H(十进制为16)的乘法试图将输入变成包装 bcd(二进制编码数字)格式。稍后,代码将使用
aad
指令,该指令在 unwake bcd上运行,并且重要的是将10用作其程序的数字库,其中您的程序将用于数字基础3。您似乎期望商和剩余的两位数输出。然后,仅打印Cl和CH的2个字符是不够的。
做
为除数类似地
,但请将其放入BL准备打印。请参阅我的答案我需要使用Notepad ++中的TASM/TLINK/DOSBOX显示3个数字答案
Are you sure about "Want output" ?
or cx,3030h
does nothing to your code because those bits will already have been set, they're part of the ASCII codes from 48 to 50. For conversion purposes you would normally usesub cx,3030h
.Next your multiplication with 10h (16 in decimal) is trying to turn the input into packed BCD (binary coded digits) format. Later the code will use the
aad
instruction that operates on unpacked BCD and importantly uses 10 as its number base where your program is going for number base 3.You seem to expect a 2-digit output for both quotient and remainder. Then just printing 2 characters from CL and CH is not enough.
To do
Similarly for the divisor, but put it in BL
Ready to print. See my answer I need to show 3 digit answer Using tasm/tlink/dosbox in notepad++
您的转换算法很困惑:
,实际上,由于
mov bl,10h
,您将第一位数字乘以16。另请参见问题 8086> 8086用户输入中的简单十进制添加=“ https://stackoverflow.com/questions/70851012/how-to-convert-an-an-asci-char-char-char-char-char-char-decimal-presentation”>如何将ASCII CHAR转换为小数点代表? 。
或使用一些更通用的方法来将其转换为两个小数号以上的输入字符串转换为二进制值。请参阅宏 lodd”> lodd 有灵感。
您需要的是 turbo debugger 允许通过指令执行您的编程指令,并观察寄存器是否按预期更改。
Your algorithm for conversion is confused:
In fact you have multiplied the first digit by 16 because of
mov bl,10h
.See also questions 8086 simple decimal addition from user input or How to convert an ASCII char to a decimal representation?.
Or use some more general method to how to convert input string with more than two decimal numbers to a binary value. See the macro LodD for inspiration.
What you need is Turbo Debugger which allows to execute you program instruction by instruction and watch if the registers change as expected.