Reputation: 125
I want to print a number in a register to the screen. Furthermore I want to save it as a string of characters (bytes). So if I had a number like 150, I would want to save it at a certain address as
'1', '5', '0'
mov ebx, dword ptr[ebp+8]
; eax contains value
; ebx contains address to store characters
; here is where conversion would take place
Since it's in a register, would you have to convert it to decimal value and then separate each place?
Upvotes: 1
Views: 1064
Reputation: 194
I´am not sure how to print the ASCII's and how to separate each place. And so i only like to show how to convert the value of EAX to decimal ASCII's and store it to the address of DS:EBX. For a 32 bit value of maximum 0FFFFFFFFh we need a place for ten decimal ASCII's (4294967295). And for example if the value is decimal 150, then we get the ASCII's of "0000000150" with some "0" at the beginning.
mov cl, 0Ah ; counter for ten decimal ASCII's
mov edi, 1000000000
P1: xor edx, edx
div edi
add al, 30h ; convert to ASCII
mov esi, edx ; save remainder
mov [ebx], al ; store ASCII to the address of DS:EBX
inc ebx
mov eax, edi
mov edi, 0Ah
xor edx, edx
div edi
mov edi, eax
mov eax, esi
dec cl
jnz P1
Upvotes: 1