0

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

rkhb
  • 14,159
  • 7
  • 32
  • 60
Progrmr
  • 1,575
  • 4
  • 26
  • 44

1 Answers1

1

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).

Dmitry Reznik
  • 6,812
  • 2
  • 32
  • 27
  • I dont understand what you mean by "(or subtract to get integer from string)". I just want to display the integer 2, not the second ASCII character. Thanks, Progrmr – Progrmr Apr 17 '12 at 06:54
  • 2
    ASCII char for "2" is 50. To show integer 2 as "2" you need to add 48. To make the reverse conversion, you need to subtract 48. Thus having ASCII 51 ("3") - 48 = 3. – Dmitry Reznik Apr 17 '12 at 17:52
  • Thanks. And in another situation, say I had the number 1930, how would I display that? – Progrmr Apr 18 '12 at 05:12
  • 1
    You'd have to convert every character to it's ascii representation. – Dmitry Reznik Apr 18 '12 at 17:36