Skip to main content
\(\newcommand{\doubler}[1]{2#1} \newcommand{\binary}{\texttt} \newcommand{\hex}{\texttt} \newcommand{\octal}{\texttt} \newcommand{\prog}{\texttt} \newcommand{\lt}{ < } \newcommand{\gt}{ > } \newcommand{\amp}{ & } \)

Section11.6Assembler Listings

Most assemblers can provide the programmer with a listing file, which shows the machine code for each instruction. The command line option for the as assembler to produce an assembly listing is -al. This causes the listing to be printed to standard output (your terminal window), so you probably want to redirect this output to a file. For example, the command:


      as --gstabs -al -o assignment2.o assignment2.s > assignment2.lst

produces the listing file shown in Listing 11.6.1.

ARM GAS  assignment2.s 			page 1


   1              	@ assignment2.s
   2              	@ Assignment three ways.
   3              	@ Bob Plantz - 5 August 2016
   4              	
   5              	@ Define my Raspberry Pi
   6              	        .cpu    cortex-a53
   7              	        .fpu    neon-fp-armv8
   8              	        .syntax unified         @ modern syntax
   9              	
  10              	@ Useful source code constants
  11              	        .equ    z,-16
  12              	        .equ    local,8
  13              	
  14              	@ Constant program data
  15              	        .section  .rodata
  16              	        .align  2
  17              	formatMsg:
  18 0000 2569202B 	        .asciz	 "%i + %i = %i\n"
  18      20256920 
  18      3D202569 
  18      0A00
  19              	
  20              	@ Program code
  21 000e 0000     	        .text
  22              	        .align  2
  23              	        .global main
  24              	        .type   main, %function
  25              	main:
  26 0000 30482DE9 	        stmfd   sp!, {r4, r5, fp, lr}  @ save caller's info
  27 0004 0CB08DE2 	        add     fp, sp, 12      @ our frame pointer
  28 0008 08D04DE2 	        sub     sp, sp, local   @ allocate memory for local var
  29              	
  30 000c 7B50A0E3 	        mov     r5, 123         @ x = 123;
  31 0010 28409FE5 	        ldr     r4, yValue      @ y = 4567;
  32 0014 043085E0 	        add     r3, r5, r4      @ x + y
  33 0018 10300BE5 	        str     r3, [fp, z]     @ z = x + y;
  34              	
  35 001c 20009FE5 	        ldr     r0, formatMsgAddr  @ printf("%i + %i = %i\n",
  36 0020 0510A0E1 	        mov     r1, r5          @            x,
  37 0024 0420A0E1 	        mov     r2, r4          @            y,
  38 0028 10301BE5 	        ldr     r3, [fp, z]     @            z);
  39 002c FEFFFFEB 	        bl      printf
  40              	
  41 0030 0000A0E3 	        mov     r0, 0           @ return 0;
  42 0034 08D08DE2 	        add     sp, sp, local   @ deallocate local var
  43 0038 3048BDE8 	        ldmfd   sp!, {r4, r5, fp, lr}  @ restore caller's info
  44 003c 1EFF2FE1 	        bx      lr              @ return
  45              	
  46              	        .align  2
  47              	yValue:
  48 0040 D7110000 	        .word   4567
  49              	formatMsgAddr:
  50 0044 00000000 	        .word   formatMsg
  51
Listing11.6.1Assembler listing file, showing machine code.

The first column is the line number. The next column is the address, relative to the beginning of this function. The third column, the 32-bit numbers, is the machine code. Be careful to remember that the machine code is shown in byte order not word order and that the ARM in the Raspberry Pi uses little endian memory storage.