开发者

Print double word number to base 10

开发者 https://www.devze.com 2023-01-28 05:24 出处:网络
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.

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 开发者_C百科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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消