I am trying to pass a char array into an x86_64 assembler program and modify it having the result available for printing in the calling c program. I am just learning assembler and haven't had much success accomplishing this. I am running Ubuntu 20.04 and using gcc and nasm compilers. The c program is as follows:
#include <stdio.h>
extern void task(char *str, char *buf);
int main(int argc, char** argv){
if (argc || argv[0]){}
printf("\n%s\n",argv[0]);
char buffer[256] = {"LJKM"};
task("ABCDEFG", buffer);
printf("\n>>%s\n",buffer);
return 0;
}
The assembler program so far is:
section .data
string1 db 0xa, " Hello StackOverflow!!!", 0xa, 0xa, 0
section .text
global task
task:
push rbp
mov rsi, qword(string1)
pop rbp
ret
I have run gdb and can see that the pointer to the string "LKJM" is passed to the assembler program in register rsi. And just prior to returning to the caller, the value pointed to by the register rsi is the "Hello Stackoverflow" string. but when the buffer is printed inside the caller, it is still "LKJM". Why doesn't the data persist? What is the correct way to accomplish this task?
-