10.6.4. Code listings for example 3

Example 10.7. : startup.s

        AREA    asm_code, CODE
; If assembled with ARMASM -16 the variable {CONFIG} will be set to 16
; If assembled with ARMASM the variable {CONFIG} will be set to 32
; Set the variable THUMB to TRUE or false depending on whether the
; file is being assembled for ARM or Thumb.
        GBLL    THUMB
    [ {CONFIG} = 16
THUMB   SETL    {TRUE}
; If assembling with ARMASM -16 go into 32 bit mode as the ARMulator will
; start up the program in ARM state.
        CODE32
    |
THUMB   SETL    {FALSE}
    ]
        IMPORT  C_Entry
        ENTRY
; Set up the stack pointer to point to the 512K.
        MOV     sp, #0x80000
; Get the address of the C entry point.
        LDR     lr, =C_Entry
        [ THUMB
; If building a Thumb version pass control to C_entry using the BX
; instruction so the processor will switch to THUMB state.
        BX      lr
    |
; Otherwise just pass control to C_entry in ARM state.
        MOV     pc, lr
    ]
        END

Example 10.8. : print.c

#include <stdio.h>
#ifdef __thumb
/* Define Angel Semihosting SWI to be Thumb one */
#define SemiSWI 0xAB
#else
/* Define Angel Semihosting SWI to be ARM one */
#define SemiSWI 0x123456
#endif
/* We use the following Debug Monitor SWIs in this example */
/* Write a string */
__swi(SemiSWI) void _Write0(unsigned op, char *string);
#define Write0(string) _Write0 (0x4,string)
/* Exit */
__swi(SemiSWI) void _Exit(unsigned op, unsigned except);
#define Exit() _Exit (0x18,0x20026)
void C_Entry(void)
{
    int i;
    char buf[20];
    for (i = 0; i < 10; i++) {
          sprintf(buf, "Hello, World %d\n", i);
          Write0(buf);
    }
    Exit();
}
Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D
Non-Confidential