【发布时间】:2014-11-03 19:02:00
【问题描述】:
我正在尝试使用scanf 和printf 编写一个简单的程序,但它没有正确存储我的值。
extern printf
extern scanf
SECTION .data
str1: db "Enter a number: ",0,10
str2: db "your value is %d, squared = %d",0,10
fmt1: db "%d",0
location: dw 0h
SECTION .bss
input1: resw 1
SECTION .text
global main
main:
push ebp
mov ebp, esp
push str1
call printf
add esp, 4
push location
push fmt1
call scanf
mov ebx, eax ;ebx holds input
mul eax ;eax holds input*input
push eax
push ebx
push dword str2
call printf
add esp, 12
mov esp, ebp
pop ebp
mov eax,0
ret
由于某种原因,当我运行程序时,无论我输入什么数字,程序都会为两个输入打印 1。
我正在使用 nasm,与 gcc 链接
【问题讨论】: