我试图接受参数(总是是一个数字)并将其从字符串转换为 一个int,并在屏幕上打印出来。
当我用
运行我的程序时./test 3
我得到一个非常大的负值...
这就是我所拥有的:
SECTION .data
str1: db "argument = %d",0,10
SECTION .text
global main
extern printf
main:
enter 0,0
pusha
mov eax, dword [ebp+12]
add eax, 4
mov bl,[eax] ; put the one bit into bl
sub ebx, '0' ; subtract null terminating string to convert to int
push ebx
push str1
call printf ; print the string
add esp, 8
popa
leave
ret
答案 0 :(得分:1)
xor ebx, ebx ; Clear ebx to zero, so the following operation will not have random values in the higher part of ebx
mov bl,[eax] ; put the one bit into bl
sub ebx, '0' ; subtract null terminating string to convert to int