0

Here is the question that I am stuck on, or rather don't seem to understand..

Q.) Write assembly code to implement the following function calls, using C/UNIX calling conventions. Show the contents of the stack on entering the called function

int myfunc2(int,char*); //prototype
...
char[] bob=”Bob's your uncle!”;
...
myfunc2(18, bob); //function call

Heres the extent of what I understand, function parameters are passed from the end to the front. Also since the parameters are not a 32 bit quantity only the address of the beginning of the array is pushed onto the stack So the parameters would be pushed onto the stack like so..

|-----------------------------------|
|             bob (address)         |
|-----------------------------------|
|             18                    |
|-----------------------------------|

This is what I think the contents of the stack would look like, an alternative would be adding addresses of all the contents of array bob into the stack. The powerpoint slide where I am learning from is not too clear on this and there is not further examples, I just want to make sure my understanding of the subject is correct before I proceed further. Thanks! Any help or guidance would be much appreciated.

Edward Lim
  • 763
  • 9
  • 31
  • 1
    Why don't you generate the assembly with `-S` switch for *gcc*? – Iharob Al Asimi Oct 21 '16 at 03:07
  • 1
    Look up "array decay". Indeed, `bob` is `char*` internally, and that pointer value is pushed on to the stack. – Dai Oct 21 '16 at 03:07
  • thanks Dai, I wasnt sure what keyword to use. So your saying that what I have drawn out is indeed correct? Also Im really new to this so Im not sure what gcc is – Edward Lim Oct 21 '16 at 03:09
  • That drawing doesn't specify where is top of stack, and the task is "after calling", so you probably should add the return address at top. – Ped7g Oct 21 '16 at 13:03
  • gcc is a very popular C compiler. – fuz Oct 21 '16 at 16:17

0 Answers0