Microprocessor Design and the ARM

Example ARM Assembly Language Program

  AREA Example, CODE, READONLY ; name the code block
  ENTRY ; marker of first executable instruction
   
start   ; label
  MOV r0, #11 ; put the value 11 in register 0
  MOV r1, #31 ; put the value 31 in register 1
  ADD r0, r0, r1 ; r0 = r0 + r1
    ; add values in r0 and r1 together
    ; and store total back into r1
  SWI 0x11 ; terminate the program
  END ; marks the end of the file

Looking at the second MOV instruction, "MOV" is the opcode for loading a value into a register. "r1" and "#31" are the operands for this instruction. "r1" is the destination register where the value will be placed. "#31" is the decimal number 31. Decimal values can be indicated by a preceding "#" or "#d". Hexadecimal numbers are indicated by a preceding "#h".

MOV, ADD and SWI are all opcodes that are understood by the microprocessor. SWI is a "software interrupt", which when followed by "0x11" as the operand value, causes the program to exit cleanly and return to the ARM debugger.

AREA, ENTRY and END are directives. Directives are instructions to the assembler. They are not passed on to the actual microprocessor.

The AREA directive can be used to specify and name sections of program code or data. The example is a code segment and indicated as such by the CODE identifier. It is also declared as READONLY in that the code cannot be altered during its execution. A working ARM assembly program must have at least one CODE area.

The ENTRY directive indicates the first instruction that should be executed within an application. The complete application can only have one entry point and so only one ENTRY directive need be issued.

The END directive demarcates the end of the application.