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

我怕爱的太早我们不能终老 提交于 2019-12-13 03:33:41

问题


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


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



来源:https://stackoverflow.com/questions/10172215/x86-assembly-how-to-show-the-integer-2-not-the-second-ascii-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!