Search code examples
assemblyx86masm32

x86 assembly (masm32) - how to split multi-digit data into individual characters


I am still getting my head around x86 assembly, and so I have made this little program that multiplies 6 and 7, moves the data to EAX and then prints the result. It compiles fine, and runs fine, but instead of printing 42, it prints the fourty-second ASCII character. I have on this forum how to print a single-character number, but now I need to figure out how to print multi-digit numbers. Here is my code:

.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
    adrs dd 0
.code
start:
    mov eax, 6
    mov ebx, 7
    imul eax, ebx
    add eax, 48
    mov adrs, eax
    invoke StdOut, addr adrs
    invoke ExitProcess, 0
end start

So in summary, I need to understand how to split data into individual characters, so that I can print them. Any help would be great.

Regards,

Progrmr


Solution

  • Divide your number by 10 repeatedly. Collect remainders. Add to them ASCII code of '0', print.