3.3.2. Using the assembler from the command line

The basic syntax to use the ARM assembler (armasm) from the command-line is:

armasm Space{inputfile}

For example, to assemble the code in a file called myfile.s, type:

armasm -list myfile.lst myfile.s

This produces an object file called myfile.o, and a listing file called myfile.lst.

For full details of the command-line options and syntax, refer to the ADS Assembler Guide.

Example 3.1 shows a small interworking ARM/Thumb assembly language program. You can use it to explore the use of the assembler, linker, and the ARM symbolic debugger.

Example 3.1. 

     AREA     AddReg,CODE,READONLY        ; Name this block of code.
     ENTRY                  ; Mark first instruction to call.
main
     ADR r0, ThumbProg + 1  ; Generate branch target address and set bit 0
                            ; hence arrive at target in Thumb state.
     BX r0                  ; Branch and exchange to ThumbProg.
     CODE16                 ; Subsequent instructions are Thumb code.
ThumbProg
     MOV r2, #2             ; Load r2 with value 2.
     MOV r3, #3             ; Load r3 with value 3.
     ADD r2, r2, r3         ; r2 = r2 + r3
     ADR r0, ARMProg        ; Generate branch target address with bit 0 zero.
     BX r0                  ; Branch and exchange to ARMProg.
     CODE32                 ; Subsequent instructions are ARM code.
ARMProg
     MOV r4, #4
     MOV r5, #5
     ADD r4, r4, r5
stop MOV r0, #0x18          ; angel_SWIreason_ReportException
     LDR r1, =0x20026       ; ADP_Stopped_ApplicationExit
     SWI 0x0123456          ; ARM semihosting SWI 
     END                    ; Mark end of this file.

Building the example

To build the example:

  1. Enter the code using any text editor and save the file in your current working directory as addreg.s.

  2. Type armasm -list addreg.lst addreg.s at the command prompt to assemble the source file.

  3. Type armlink addreg.o -o addreg to link the file.

Running the example in the debugger

To load and run the example in the debugger:

  1. Type armsd addreg to load the module into the command-line debugger.

  2. Type step to step through the rest of the program one instruction at a time. After each instruction, you can type reg to display the registers.

When the program terminates, to return to the command line, type quit.

For further details on ARM and Thumb assembly language programing, see the ADS Assembler Guide.

Copyright © 1999-2001 ARM Limited. All rights reserved.ARM DUI 0064D
Non-Confidential