next up previous contents

[ENGN3213 Home]

Subroutines

In CLAB6 we learnt about assembly language subroutines, parameter passing, and stack frames. We now look at some C programs with subroutines and see how the C compiler handles them.

Download the C program clab72c.c:

/*      clab72c.c, Clements, page  160 */

int adder(int x, int y)
{
     return x + y;
}

int main()
{
  int a, b, c;
  a = 1; b =  2;
  c = adder(a, b);
}

Exercise.

1.
Compile, assemble and link this program.

2.
What does this program do?

3.
Load the program clab72c.s19 into the BSVC simulator. Run the code and check for correct operation.

4.
Examine the assembly code produced by the compiler in the file clab72c.s (or in the listing file clab72c.lst). How are the variables stored in main and adder?

5.
How are parameters passed to the subroutine? What are they? Are they passed by value or reference?


next up previous contents

[ENGN3213 Home]

ANU Engineering - ENGN3213