next up previous contents

[ENGN3213 Home]

A C Example

Using a text editor, enter the following C program into a file hello.c:

/*   hello.c */
#include <stdio.h>

int main() {
      printf("Hello from sea world!\n");    /* call C function printf */
      return 0;
}

Compile, assemble and link the program in a DOS window by typing:

m68k-coff-gcc -S hello.c -o hello.s -m5200
m68k-coff-as hello.s -o hello.o -m5200 -ahls=hello.lst
m68k-coff-gcc -m5200 -Wl,-s -Wl,-n -Tsbc5206-srec.ld hello.o -o hello.x

You can also use the script file sbc-c.bat, or create a make file.

Exercise.

1.
Load the program hello.x into the SBC.

2.
Run the code and check for correct operation:
go 10000

3.
Explain all items of syntax used.

4.
What does the program do?

5.
Examine the assembly code produced by the compiler in hello.s or hello.lst. What methods for parameter passing are used? What addressing modes are used? Compare with hellos.s.


next up previous contents

[ENGN3213 Home]

ANU Engineering - ENGN3213