Skip to main content

Section 11.6 Assembler 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              	@ 2017-09-29: Bob Plantz
   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              	        .text
  22              	        .align  2
  23              	        .global main
  24              	        .type   main, %function
  25              	main:
  26 0000 0CD04DE2 	        sub     sp, sp, 12      @ space for saving regs
  27 0004 00B08DE5 	        str     fp, [sp, 0]     @ save fp
  28 0008 04E08DE5 	        str     lr, [sp, 4]     @      lr
  29 000c 08508DE5 	        str     r5, [sp, 8]     @      r5
  30 0010 0C408DE5 	        str     r4, [sp, 12]    @   and r4
  31 0014 0CB08DE2 	        add     fp, sp, 12      @ our frame pointer
  32 0018 08D04DE2 	        sub     sp, sp, local   @ allocate memory for local var
  33              	
  34 001c 7B50A0E3 	        mov     r5, 123         @ x = 123;
  35 0020 38409FE5 	        ldr     r4, yValue      @ y = 4567;
  36 0024 043085E0 	        add     r3, r5, r4      @ x + y
  37 0028 10300BE5 	        str     r3, [fp, z]     @ z = x + y;
  38              	
  39 002c 30009FE5 	        ldr     r0, formatMsgAddr  @ printf("%i + %i = %i\n",
  40 0030 0510A0E1 	        mov     r1, r5          @            x,
  41 0034 0420A0E1 	        mov     r2, r4          @            y,
  42 0038 10301BE5 	        ldr     r3, [fp, z]     @            z);
  43 003c FEFFFFEB 	        bl      printf
  44              	
  45 0040 0000A0E3 	        mov     r0, 0           @ return 0;
  46 0044 08D08DE2 	        add     sp, sp, local   @ deallocate local var
  47 0048 00B09DE5 	        ldr     fp, [sp, 0]     @ restore fp
  48 004c 04E09DE5 	        ldr     lr, [sp, 4]     @      lr
  49 0050 08509DE5 	        ldr     r5, [sp, 8]     @      r5
  50 0054 0C409DE5 	        ldr     r4, [sp, 12]    @      r4
  51 0058 0CD08DE2 	        add     sp, sp, 12      @   and sp
  52 005c 1EFF2FE1 	        bx      lr              @ return
  53              	
  54              	        .align  2
ARM GAS  assignment2.s 			page 2


  55              	yValue:
  56 0060 D7110000 	        .word   4567
  57              	formatMsgAddr:
  58 0064 00000000 	        .word   formatMsg
  59
Listing 11.6.1. Assembler 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.