Introduction to ARM Assembly Language

Embedded System Basics

Definition

Embedded System: Any device that includes a programmable computer but is not itself a general purpose computer.

An alternate definition: A computing system, specialized for only a few applications with none (or minimum) end user programmability, embedded into a larger product.

The main purpose of the product with an embedded system is not computing.

Design objectives

Embedded vs General Purpose System

_ Embedded Systems General Purpose Systems
Number of applications Few (known at design time) Broad range of applications
Programmable by end user? No Yes
Performance requirements Fixed (additional performance not useful) Higher performance is useful (enables new applications)
Design criteria Cost, Power consumption, Worst case speed, Size and weight, Dependability Cost, Power consumption, Average speed

Embedded System Design

Embedded system design flow

Requirements

Informal description of the system in layman's language.

Specification

An unambigous technical description derived from Requirements. Detailed enough to design the system architecture.

Architecture

A high level overview of system structure in terms of components needed and their interaction.

Key challenge: How to distribute the functionality among hardware and software to meet the competing requirements: cost, performance, power, etc.

Components

Choose or build the components to implement the Architecture and meet the Specifications.

Integration

Put the components together and make the system work!

Key challenge: Unforeseen bugs may appear during integration.

Embedded System: Programming the hardware

Assembly Programming Introduction

In this course, we will examine ARM ISA (Instruction Set Architecture) to learn assembly.

Instruction Set Architecture (ISA)

Machine and assembly instructions

Assembly code example

Hight level language (c/Java)

a[0] = b[0] + 5;

Assembly code:

ldr r3, [r1]  ; get the value to b[0] from memory to r3
add r4, r3, 5 ; add 5 to b[0] and store in r4
str r4, [r2]  ; save r4 to a[0]

Things to notice:

ARM architecture (ISA)

The Thumb-2 architecture will be used in the labs of this course.

Registers

Thumb-2 Instruction Categories

More details in the text book and Thumb-2 manuals!

Writing your first assembly program

Preparing to write an assembly program

High level language statement:

g = A[1] + 5
; offset in number of bytes, for int32: 4 bytes
ldr r3, [r2, #4] ; r3 = r2[1]
add r4, r3, #5   ; r4 = r3 + 5

Writing an assembly program

High level language program:

int a[2] = {10, 20};
int x;
x = a[0] + a[1];
.section .text
  ldr r1, =a ; ldr is a pseudo-op here, loading the address of a
  ldr r2, [r1]
  ldr r3, [r1, #4]
  add r4, r2, r3
  ldr r1, =x
  str r4, [r1]

.section .data
a:
  .word 10 ; a[0]
  .word 20 ; a[1]
x:
  .word 0 ; x

Memory addressing: Endianness