将双字编号打印到10

时间:2010-12-05 10:51:27

标签: assembly dos tasm

例如我的号码是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位寄存器

2 个答案:

答案 0 :(得分:2)

  

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

确实不会。你需要做的是用两个单词来表示大数字的表示。即,您需要实现多精度分割,并将其用于除以10的分割。

有关如何执行此操作的提示,请查看this question的已接受答案。

答案 1 :(得分:1)

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

相关问题