0

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!

1
  • In your assembly, you push the pointer value onto the stack just prior to calling printf. But I don't see where you are pushing a formatting string. Don't you effectively need to push "%x\n" onto the stack as well? Commented Mar 10, 2013 at 4:25

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.