10.4. Example 1: Building a ROM to be loaded at address 0

This example shows how to construct a piece of code suitable for running from ROM. In a real example, much more would have to go into the initialization section, but because the initialization process is very hardware-specific, it has been omitted here.

The code for init.s and ex.c is in the Examples\ROM\init subdirectory of your SDT install directory (normally c:\ARM250\Examples\ROM\init), and is included in Sample code for reference.

  1. Compile the C file ex.c with the following command.

    armcc -c ex.c  (ARM)

    tcc -c ex.c    (Thumb)



    tells the compiler to compile only (not to link).

  2. Assemble the initialization code init.s.

    armasm -PD "ROM_AT_ADDRESS_ZERO SETL {TRUE}" init.s

    or, for Thumb:


    This tells the assembler to predefine (-PD) the symbol ROM_AT_ADDRESS_ZERO and to give it the logical (or Boolean) value TRUE.


    On UNIX systems, use single quotes (‘) instead of double quotes (“), or put a backslash before any double quotes. For example:


    The assembler file init.s tests this symbol and generates different code depending on whether or not the symbol is set. If the symbol is set, it generates a sequence of branches to be loaded directly over the vector area at address 0.

  3. Link the image using the following command:

    armlink -o rom0.axf -ro-base 0x0 -rw-base  0x10000000 
    -first init.o(Init) -map -info Sizes init.o ex.o 

    or, for Thumb:

    armlink -o trom0.axf -ro-base 0x0 -rw-base 0x10000000
    -First init.o(Init) -map -info Sizes init.o ex.o



    specifies the output file.

    -ro-base 0x0

    tells the linker that the read-only or code segment will be placed at 0x00000000 in the address map.

    -rw-base 0x10000000

    tells the linker that the read-write or data segment will be placed at 0x10000000 in the address map. This is the base of the RAM in this example.

    -first init.o(Init)

    tells the linker to place this area first in the image. On UNIX systems you might need to put a backslash \ before each parenthesis.


    tells the linker to print an area map or listing showing where each code or data section will be placed in the address space. The output is shown in Area listing for the code.

    -info Sizes

    tell the linker to print information on the code and data sizes of each object file along with the totals for each type of code or data. The output generated is shown in Output from -info Sizes option.

  4. Run the fromELF utility to produce a plain binary version of the image:

    fromelf -nozeropad rom0.axf -bin rom0.bin   (ARM)

    fromelf -nozeropad trom0.axf -bin trom0.bin (Thumb)



    tells the linker not to pad the end of the image with zeros to make space for variables. This option should always be used when building ROM images.


    specifies a binary output image with no header.

  5. Load and execute the ROM image under ARMulator by starting armsd, ADW, or ADU, then type the following on the command line:

    getfile rom0.bin 0   (ARM)

    getfile trom0.bin 0  (Thumb)


Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D