next up previous contents

[ENGN3213 Home]

A First Example

Download the C program clab71c.c:

/*      clab71c.c (Clements, page 145) */

int main() {
           int i,j;
           i = 1;
           j = 2;        
           return i + j;
}

Examine the syntax, and determine what the program does.

You can compile, assemble and link this program by typing the following commands in your terminal window:

m68k-coff-gcc -S clab71c.c -o clab71c.s -m68000
m68k-coff-as clab71c.s -o clab71c.o -m68000 -ahls=clab71c.lst
m68k-coff-ld clab71c.o -o clab71c.s19 -L. -Tbsvc-unix.ld

Exercise.

1.
Load the program clab71c.s19 into the BSVC simulator. Run the code and check for correct operation.

2.
Examine the assembly code produced by the compiler in the file clab71c.s (or in the listing file clab71c.lst). What is the size of the int variables? How are they stored and manipulated? How is the stack frame used?

3.
Edit the variable declaration line as follows:

register      int i,j;

Recompile, assemble and link. Run the code and check for correct operation. How are the variables stored now? How is the stack frame used?


next up previous contents

[ENGN3213 Home]

ANU Engineering - ENGN3213