Reputation: 151
I am trying to pass an array to my sorting program written in assembly. The code i have so far is:
main.c:
#include <stdio.h>
extern void myFunc(int * somedata);
int arr[5] = { 3, 2, 33, 11, 1};
void main(){
int i;
myFunc(arr);
for(i = 0; i < 5; i++)
{
// printf( "%d\n", arr[i] );
}
}
myFunc.asm:
section .text global myFunc extern printf
myFunc:
enter 4,0
push ebx
push dword [ebp + 8]
call printf
pop ebx
leave
ret
This is just some testing code to get learn how to do this.
My understanding would be that this should print the pointer to the array but I'm probably wrong.
Can anyone give me a simple example of passing an array to an assembly file (NASM).
Thank you!
Upvotes: 0
Views: 1522
Reputation: 11791
The best way to answer such questions is to write a short function that does the types of operations you are interested in in C, and compile that to assembly to do reverse engineering.
Upvotes: 2
Reputation: 137398
You're calling printf
with the first argument being the pointer that was passed to myFunc
. That's not going to work - the first argument has to be a format string.
The rest of your code looks okay though. Note, you're going to have to pass the length of the array to your asm function, too.
Upvotes: 2