Progrmr
Progrmr

Reputation: 1621

x86 assembly - how to show the integer 2, not the second ASCII character

I have this 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
num dd ?
.code
start:
mov eax, 1
mov ebx, 1
add eax, ebx
push eax
pop num
sub num, 0
invoke StdOut, addr num
invoke ExitProcess, 0
end start

What it is supposed to do is do 1+1 and then display the result on the console. When I run it it displays the ASCII character for 2 (the second ASCII character), not the number 2. I don't know how to get it to show the number 2, not the second ASCII character. How do i do that?

Thanks in advance,

Progrmr

Upvotes: 0

Views: 1042

Answers (1)

Dmitry Reznik
Dmitry Reznik

Reputation: 6862

You could declare your variable as string:

.data
num DB '2',0 ; maps "2" and a null-symbol to num

Also you could add 48 to your number (and that would give correct ASCII number) (or subtract to get integer from string).

Upvotes: 1

Related Questions