1

I'm just having a small issue with a problem that they gave me. Basically, I have a C file with the following statement:

int my_pid;
// Print the process' PID
GetPID(&my_pid);
printf("My PID is %d.\n", my_pid);

In a separate .asm file, I have the following function:

global GetPID
GetPID:
    ; Implementation goes here...
    ret

How do I make it so that I can use the variable "my_pid" in the asm file?

Everything is already properly linked in the makefile so it's more of an issue that I don't know enough assembly and I haven't found any clear explanation on this topic.

Any help is greatly appreciated!

ProTimmy
  • 19
  • 1
  • You don't want to use the C variable. Notice you get passed a pointer as argument. THAT is what you want to use. – Jester Jan 14 '17 at 21:05
  • @Jester Yes I'm sorry, I do understand that part but then I just don't know how to access that point in memory in the asm file, thanks for the clarification tho – ProTimmy Jan 14 '17 at 21:08
  • That depends on the calling convention. Normally in 32 bit mode it gets passed on the stack, so you can load it like `mov eax, [esp+4]` and then dereference it as usual by `[eax]`. – Jester Jan 14 '17 at 21:16
  • @Jester Alright, so just to clarify the final code would look something like this? (for example setting my_pid=1) `mov eax, [esp+4]; mov [eax], 1` – ProTimmy Jan 14 '17 at 21:36
  • Yes that's right. – Jester Jan 14 '17 at 21:36

0 Answers0