打印以 10 为基数的双字数字
例如,我有数字 6C0000h = 7077888d
在这种情况下,将每个字除以 10,然后将余数保存在堆栈上是行不通的,因为双字的下部是 0000。
任何提示都值得赞赏。
谢谢
例如..
;number = 6c0000h
mov ax,word ptr number
;after this mov ax is 0000
;dividing by ten will mean dx = 0 and ax = 0 and 0 is saved on the stack
mov cx,0
repeat:
mov dx,0
div ten ;ten = 10
inc cx
push dx
cmp ax,0
ja repeat
mov ax,word ptr number+2
;after this ax is 6Ch
;i think this part is alright
repeat2:
mov dx,0
div ten
inc cx
push dx
cmp ax,0
ja repeat2
display:
pop dx
add dl,'0'
mov ah,02h
int 21h
loop display
此代码显示:1080而不是7077888,这将是预期结果
108 = 6Ch,结尾0来自0000 div 10..
注意:我必须使用16位寄存器
For example I have the number 6C0000h = 7077888d
Dividing each word by ten and then saving the remainder on the stack doesn't work in this case, because the lower part of the double word is 0000.
Any tips are appreciated.
thanks
for example..
;number = 6c0000h
mov ax,word ptr number
;after this mov ax is 0000
;dividing by ten will mean dx = 0 and ax = 0 and 0 is saved on the stack
mov cx,0
repeat:
mov dx,0
div ten ;ten = 10
inc cx
push dx
cmp ax,0
ja repeat
mov ax,word ptr number+2
;after this ax is 6Ch
;i think this part is alright
repeat2:
mov dx,0
div ten
inc cx
push dx
cmp ax,0
ja repeat2
display:
pop dx
add dl,'0'
mov ah,02h
int 21h
loop display
this code displays: 1080 and not 7077888 which would be the expected result
108 = 6Ch and the ending 0 is from 0000 div 10..
NOTE: I have to work with 16bit registers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,确实行不通。您需要做的就是用两个词来表示大量的除法。即,您需要实现多精度除法,并将其用于除以 10。
有关如何执行此操作的提示,请查看 这个问题。
No indeed it won't. What you need to do is implement division for your representation of a large number in two words. I.e., you need to implement multiple-precision division, and use that for your division by 10.
For hints of how to do this, look at the accepted answer to this question.
为什么不分工呢?你知道,你可以用 0 除以 10。
Why wouldn't dividing work? You can devide 0 by 10, you know.