0
首先我要感謝任何回覆此消息的人,非常感謝您的幫助!Sscanf不能從命令行參數字符串轉換爲IEEE浮點數Nasm x86程序集
我想獲得命令行參數(在下面的代碼中,只有一個參數),並使用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
再次感謝!
我改變了我推送參數到你說的,並且它的工作的順序。謝謝! – Tom