我想在NASM彙編程序中使用strstr C函數,但似乎無法使其正確打印出來。我嘗試了多種變化,但我想我可能會誤解NASM如何從C返回指針值,因爲我在printf或'(null)'中返回空行。爲什麼我無法獲得正確的印刷回報值?有些人可以幫我填補嗎?在NASM中使用strstr()的返回值?
section .data
str1 db "Here is some text with a word",0x0A,0x00
str2 db "text",0x0A, 0x00
strFmt db "%s",0x0A,0x00
global _start
extern printf
extern strstr
section .text
_start:
push ebp
mov ebp, esi
push str2
push str1
call strstr
add esp, 8
mov dword [myString], eax
push dword [myString]
push strFmt
call printf
add esp, 8
_exit:
mov ebx, 0
mov eax, 1
int 0x80
這看起來像一個錯字:'mov ebp,esi'。我敢打賭,你的意思是來源於'esp'那裏。另外,什麼是'myString'?即使您使用它,這也未在您所展示的代碼中定義。爲什麼不直接'直接推eax'? –
我看到你使用'int 0x80',所以我認爲這是Linux或macOS。請下次在您的問題中添加此信息。 Windows上的情況稍有不同。 –