4.1.4. Generating interleaved C and assembly language

Follow these steps to generate interleaved C and assembly language:

  1. Quit the debugger if it is running.

  2. Enter armcc -S -fs hello.c at the system prompt.

    The -S option instructs armcc to write out an assembly language listing of the instructions that would usually be compiled into executable code. The -fs option instructs the compiler to interleave C and the generated assembly language.

    By default, the output file will have the same name as the C source file, but with the extension .s.

  3. Display the file hello.s on screen using the appropriate operating system command, or load it into a text editor. Example 4.1 shows the assembly language generated for hello.c.


    Your code may differ slightly from Example 4.1, depending on the version of compiler you are using.

Example 4.1. 

|x$codeseg| DATA
;;;1      #include <stdio.h>
;;;3      int main (void)
;;;5      {
000000  e52de004          STR      lr,[sp,#-4]!
;;;7      printf ("Hello world\n");
000004  e28f0f02          ADD      a1,pc,#L000014-.-8
000008  ebfffffc          BL       _printf
;;;9      return 0;
00000c  e3a00000          MOV      a1,#0
000010  e49df004          LDR      pc,[sp],#4
000014  6c6c6548          DCB      0x48,0x65,0x6c,0x6c         ; 'Hell'
000018  6f77206f          DCB      0x6f,0x20,0x77,0x6f         ; 'o wo'
00001c  0a646c72          DCB      0x72,0x6c,0x64,0x0a         ; 'rld\n'
000020  00000000          DCB      0x00,0x00,0x00,0x00         ; '\0\0\0\0'
;;;10     }
Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D