【发布时间】:2013-12-09 05:45:54
【问题描述】:
首先我要感谢任何回复此问题的人,非常感谢您的帮助!
我正在尝试获取命令行参数(在下面的代码中,只有一个参数)并使用 sscanf() 将它们转换为浮点数。我传递了我想在 (temp) 中存储浮点数的位置的地址、一个指向我希望转换的字符串的指针 (dword [ecx + 4]) 以及格式字符串。但是,在调用 sscanf() 之后,我发现我初始化 temp 的值没有改变。显然,我使用 sscanf() 不正确。我究竟做错了什么?
EXTERN printf
EXTERN sscanf
GLOBAL main
SEGMENT .data
formd: DB "%d", 10, 0
formf: DB "%f", 10, 0
format: DB "%f", 0
temp: DD 1.1235 ; where I want the number to go, initialized with some arbitrary non zero number
SEGMENT .text
main:
push ebp
mov ebp, esp
mov ebx, [ebp + 8] ; number of params
mov ecx, [ebp + 12] ; &(parameter table)
pushad ; print out the number of parameters
push ebx
push formd
call printf
add esp, 8
popad
pushad ; get number
push temp ; pass the address of the destination
push dword [ecx + 4] ; pass the first command line parameter
push format ; pass the format string
call sscanf ; convert it to floating point
add esp, 12
popad
pushad ; print out temp with FPU
finit
fld dword [temp]
sub esp, 8
fstp qword [esp]
push formf
call printf
add esp, 12
popad
pop ebp
ret
再次感谢!
【问题讨论】:
标签: assembly x86 command-line-arguments nasm scanf