打印以 10 为基数的双字数字

发布于 2024-10-06 10:17:35 字数 749 浏览 5 评论 0原文

例如,我有数字 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

金兰素衣 2024-10-13 10:17:35

在这种情况下,将每个字除以 10,然后将余数保存到堆栈中不起作用,因为双字的低位部分是 0000。

不,确实行不通。您需要做的就是用两个词来表示大量的除法。即,您需要实现多精度除法,并将其用于除以 10。

有关如何执行此操作的提示,请查看 这个问题

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.

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.

久隐师 2024-10-13 10:17:35

为什么不分工呢?你知道,你可以用 0 除以 10。

Why wouldn't dividing work? You can devide 0 by 10, you know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文