next up previous contents

[ENGN3213 Home]

Calling a C Function from Assembler

The gcc cross development system includes a wide range of standard C functions that are available to the user. Let's look at an example of an assembly program which calls the C function printf.

Download the assembly program hellos.s:

/*    hellos.s    */

      .text
      .even

      .global  main
main: pea    words          /* push address of char string on stack */
      jsr printf            /* jump to C function printf */
      addq.l #4,%a7         /* clean up stack on return */
      rts

words:   .ascii   "Hello from assembly world!\n\0"

Note that the string words is terminated by the null character $\backslash$0, C style.

Exercise.

1.
Assemble and link the program.

2.
Load the program hellos.x into the SBC.

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

4.
What does the program do?

5.
What methods for parameter passing are used? What addressing modes are used?

6.
Try single stepping through the code. You will need to step over printf!


next up previous contents

[ENGN3213 Home]

ANU Engineering - ENGN3213