0

コマンドライン引数から不明な数の float 値を取り、それらを加算する単純なプログラムを NASM に実装しようとしています。これは私にとってはうまくいかないようです.atof呼び出しを間違って使用している可能性があります. atof 呼び出しの後にフロートを出力して、それらが機能していることを確認しましたが、入力した数値を取得できませんでした。さらに、これらの出力された数値の合計も取得していないため、そこにも何か問題があります。私は同様のコードのサンプルを探しましたが、残念ながら NASM は Java とほぼ同じようにオンラインで文書化されていません。

これが私のコードです:

extern atof
extern printf
extern exit

global main

section .data
formats: db "%s", 10, 0
formatd: db "%d", 10, 0
formatf: db "%f", 10, 0

debug1: db "fell through copy loop.", 10, 0
debug2: db "fell through location.", 10, 0

section .bss
floatAvg: resq 1
numArgs: resd 1


tempFlt1: resq 1
tempFlt2: resq 1

section .text
main:


mov ecx, [esp + 4]
dec ecx
mov dword [numArgs], ecx

mov ebx, [esp + 8]
add ebx, 4


;no output if no args
cmp ecx, 0
je endProg


;find the sum
dec ecx

FINIT
FLDZ ; sum is zero

sumLoop:
push ecx ;preserve

push dword [ebx]
call atof
add esp, 4
FSTP qword [tempFlt1]

;debug
FLD dword [tempFlt1]
sub esp, 8
FSTP qword [esp]
push formatf
call printf
add esp, 12


FADD qword [tempFlt1]

pop ecx ;restore
dec ecx
add ebx, 4

cmp ecx, 0
jge sumLoop

FSTP qword [tempFlt2]

FLD dword [tempFlt2]
sub esp, 8
FSTP qword [esp]
push formatf
call printf
add esp, 12


endProg:
call exit

入力/出力の例:

中: 4 7 8 9

出力: 0.0 0.0 0.0 0.0、合計 0.0

中: 7.3 6.9

出力: 0.0 -0.0、合計 272008302207532160516096.0

中: 8.8 6.3 3.98

出力: -0.0 0.0 0.058750、合計 -230215375187831947264.0

4

0 に答える 0