我试图在Linux中将4字节整数数组从C传递给32位nasm。该函数调用以该顺序传递指向第一个整数和整数值长度的指针。 C程序从文件中读取数字列表。我已验证该数组正确填充。
运行以下代码时,我得到了一致的大数值。每个值都与最后一个相同,并且都不在原始数组中。
相关的nasm代码如下:
_sumAndPrintList:
push ebp
mov ebp, esp
sub esp, 16
push ebx
push ecx
push edx
push edi
push esi
mov ebx, [ebp + 8] ;Pointer to start of list
mov ecx, [ebp + 12] ;Size of list
push ebx
push ecx
push header ;This is a string and prints correctly
call printf
add esp, 4
pop ecx
pop ebx
xor edi, edi ;counter
xor esi, esi ;running total
printLoop:
cmp edi, ecx ;check if at end of list
je endPrintLoop
add esi, [ebx] ;add value in ebx to esi
mov [value], ebx ;move value in array to value
mov [total], esi ;put esi in total
push ebx
push ecx
push edi
push esi
push total
push value
push printNums ;string that prints the value and then the total
call printf
add esp, 12
pop esi
pop edi
pop ecx
pop ebx
add ebx, dword 1
inc edi
jmp printLoop
所有内容都能正确打印,只是值有误而总数是错误的。我对组装还是很陌生,因此,如果我加入的内容太多或太少,或者您有任何疑问,请随时询问/让我知道。