I am trying to use the strstr C function in a NASM assembly program but cannot seem to get it to print out correctly. I have tried multiple variations of this, but I think I may be misinterpreting how NASM returns the pointer value from C as I either get a blank line returned in the printf or a '(null)'. Could some help fill me in as why I cannot get the correct return value to be printed?
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. I'll bet you meant for the source to beespthere. Also, what ismyString? That's not defined in the code you've shown, even though you use it. Why not justpush eaxdirectly? - Cody Grayint 0x80, so I assume this is Linux or macOS. Please, next time, add this information in your question. Things are slightly different on, say, Windows. - Rudy Velthuis