Search code examples
cassemblycalling-conventionnios

Assembly's function parameter


I'm actually a beginner in assembly (Nios II) and I know that a functions parameters are stored in the registers (r4 -> r7) But I wonder if f these registers contain the actual value of the parameter or it's adress ?

for example the C function :

 int add (int x, int y) {}

Does r4 contain 'x' or '&x' ?


Solution

  • Here's the ABI for Nios II: https://www.intel.com/content/dam/www/programmable/us/en/pdfs/literature/hb/nios2/n2cpu_nii51016.pdf From the table, we can tell that arguments are passed indeed in registers r4-r7, and each one of them holds 32 bits. From the same document we learn that int is 4 bytes. That means that x will be passed in r4. &x is not passed here, as this is call-by-value. If you want to access the address of x, good compiler will try first to see if it's ever needed, and only after giving up, will allocate memory on the stack frame.