I have used one simple algorithm for converting number to string found here on SO which I have adjusted for my own purposes, but it doesn't exactly do what I need. I have a string:
string point, "xxx points"
And constant:
const10 dd 10
points dd 50 ; range from 0 - 990
The adjusted routine
mov eax, [points] ; number to be converted
.convNum:
push eax
push edx
xor edx,edx
div dword [const10] ;eax = result, edx = remainder
cmp eax, dword 0 ; test of the res
je .print
jmp .convNum
.print:
lea eax,[edx+'0']
mov [point], dword eax ; need to replace xxx in string by number
pop edx
pop eax
This one doesn't work as intended, because it shows only one digit, which I understand, but I am not able to change the routine in a way I want.
EDIT:
Adding another version of code
push eax
push edx
mov eax, [points]
.convNum:
xor edx,edx
div dword [const10]
lea eax,[edx+'0']
mov ecx,[counter]
cmp ecx, 1
jne .next
mov [point+2], byte al
mov eax,[points]
div dword [const10]
jmp .again
.next:
cmp ecx, 2
jne .next2
mov [point+1], byte al
mov eax,[points]
div dword [const10]
div dword [const10]
jmp .again
.next2:
mov ecx,[p_bodu]
cmp ecx, 100
jb .kend
mov [point], byte al
jmp .kend
.again:
inc ecx
mov [counter],ecx
jmp .convNum
.kend:
pop edx
pop eax
This code takes the number from lowest to highest. Numbers like 120 convert well, but number like 130,150 convert to 630, 650, again number 140 converts well
You keep pushing EAX and EDX in a loop. You only need to do this once.
Move the .convNum label 2 lines lower:
mov eax, [points] ; number to be converted
push eax
push edx
.convNum:
xor edx,edx
div dword [const10] ;eax = result, edx = remainder
cmp eax, dword 0 ; test of the res
jne .convNum
.print:
Also note that you should write a byte instead of a dword:
mov [point], al ;
The code you wrote will only process the highest digit of the value provided. To continu retrieving lower placed digits you need to subtract the current digit times (a multiple of) 10 from the number and repeat the code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With