User guide

6.4 The reference C example using semihosting
This example shows an application that uses the semihosting SWIs. printf() is compiled as a call to a C library
function that uses a semihosting SWI to display information on the debugger console. The application consists of a
single C file.
The code for main.c is in install_directory\Examples\Embedded\embed directory, and is included in
Example 6-1 for reference.
To build the example from the CodeWarrior IDE:
1. Use the CodeWarrior IDE project embed.mcp
2. Select Target=Semihosted.
To build the example from the command line, execute build_a.bat or follow the steps below:
1. Compile the C file main.c with one of the following commands:
armcc -g -O1 -c main.c (if compiling for ARM)
tcc -g -O1 -c main.c (if compiling for Thumb)
where:
-O1
Specifies the level of optimization.
-g
Instructs the compiler to add debug tables.
-c
Instructs the compiler to compile only (not to link).
2. Link the image using the following command:
armlink main.o -o embed.axf
where:
-o
specifies the output file as embed.axf.
3. Use ARMulator to test the image or download the image to a development board using Multi-ICE or Angel.
6.4.1 Memory map
Figure 6-3 shows the memory map of the reference example.
Figure 6-3 Memory map for reference example
By default, the linker sets the start of code at address 0x8000. The RW data is placed immediately above the
program code and the ZI data above the RW data.
Writing Code for ROM
Copyright ?1999 2001 ARM Limited 6-6