ARM Prog Model 1
ARM Prog Model 1
1
ARM instruction set architecture
ARM versions.
ARM programming model.
ARM memory organization.
ARM assembly language.
ARM data operations.
ARM flow of control.
2
ARM Architecture versions
(From arm.com)
3
Instruction Sets
4
Arm Processor Families
Cortex-A75 Cortex-A55
Cortex-A73 Cortex-A53
Cortex-A series (advanced application) Cortex-A72 Cortex-A35
High-performance processors for open OSs Cortex-A57 Cortex-A32
Cortex-A
App’s: smartphones, digital TV, server solutions, and home Cortex-A17
Cortex-A15
Cortex-A8
Cortex-A7
gateways. Cortex-A9 Cortex-A5
Cortex-M7 Cortex-M0
Cortex-M series (microcontroller) Cortex-M4 Cortex-M23
6
Programmer’s model of a CPU
What information is specified in an “instruction” to accomplish a
task?
Operations: add, subtract, move, jump
Operands: data manipulated by operations
# of operands per instruction (1-2-3)
Data sizes & types
# bits (1, 8, 16, 32, …)
signed/unsigned integer, floating-point, character …
Locations of operands
Memory – specify location by a memory “address”
CPU Registers – specify register name/number
Immediate – data embedded in the instruction code
Input/output device “ports”/interfaces
7
RISC vs. CISC architectures
CISC = “Complex Instruction Set Computer”
Rich set of instructions and options to minimize #operations
required to perform a given task
Example: Intel x86 instruction set architecture
RISC = “Reduced Instruction Set Computer”
Fixed instruction length
Fewer/simpler instructions than CISC CPU 32-bit load/store
architecture
Limited addressing modes, operand types
Simple design easier to speed up, pipeline & scale
Example: ARM architecture
8
ARM instruction format
Add instruction: ADD R1, R2, R3 ;2nd source operand = register
ADD R1, R2, #5 ;2nd source operand = constant
1 2 3 4
1. operation: binary addition (compute R1 = R2 + 5)
2. destination: register R1 (replaces original contents of R1)
3. left-hand operand: register R2
4. right-hand operand:
Option 1: register R3
Option 2: constant 5 (# indicates constant)
operand size: 32 bits (all arithmetic/logical instructions)
operand type: signed or unsigned integer
9
ARM assembly language
Fairly standard assembly language format:
memory address/pointer
10
Processor core registers
• All registers are 32 bits wide
11
Program status register (PSR)
Flags
Program Status Register xPSR is a composite of 3 PSRs:
APSR - Application Program Status Register – ALU condition flags
N (negative), Z (zero), C (carry/borrow), V (2’s complement overflow)
Flags set by ALU operations; tested by conditional jumps/execution
IPSR - Interrupt Program Status Register
Interrupt/Exception No.
EPSR - Execution Program Status Register
T bit = 1 if CPU in “Thumb mode” (always for Cortex-M4), 0 in “ARM mode”
IT field – If/Then block information
ICI field – Interruptible-Continuable Instruction information
xPSR stored on the stack on exception entry
12
Data types supported in ARM
Integer ALU operations are performed only on 32-bit data
Signed or unsigned integers
Data sizes in memory:
Byte (8-bit), Half-word (16-bit), Word (32-bit), Double Word (64-bit)
Bytes/half-words are converted to 32-bits when moved into a register
Signed numbers – extend sign bit to upper bits of a 32-bit register
Unsigned numbers –fill upper bits of a 32-bit register with 0’s
Examples:
255 (unsigned byte) 0xFF=>0x000000FF (fill upper 24 bits with 0)
-1 (signed byte) 0xFF=>0xFFFFFFFF (fill upper 24 bits with sign bit 1)
+1 (signed byte) 0x01=>0x00000001 (fill upper 24 bits with sign bit 0)
-32768 (signed half-word) 0x8000=>0xFFFF8000 (sign bit = 1)
32768 (unsigned half-word) 0x8000=>0x00008000
+32767 (signed half-word) 0x7FFF=>0x00007FFF (sign bit = 0)
Cortex-M4F supports single and double-precision IEEE floating-point data
(Floating-point ALU is optional in Cortex-M4 implementations)
13
C/C++ language data types
Type Size Range of values
(bits)
char 8 [-27 .. +27–1] = [-128 .. +127]
signed char Compiler-specific (not specified in C standard)
ARM compiler default is signed
unsigned char 8 [0 .. 28–1] = [0..255]
short 16 [-215 .. +215–1]
signed short
unsigned short 16 [0 .. 216–1]
int 32 [-231 .. +231–1] (natural size of host CPU)
signed int int specified as signed in the C standard
unsigned int 32 [0 .. 232–1]
long 32 [-231 .. +231–1]
long long 64 [-263 .. +263–1]
float 32 IEEE single-precision floating-point format
double 64 IEEE double-precision floating-point format
14
Directive: Data Allocation
16
Memory usage
Code memory (normally read-only memory)
Program instructions
Constant data
Data memory (normally read/write memory – RAM)
Variable data/operands
Stack (located in data memory)
Special Last-In/First-Out (LIFO) data structure
Save information temporarily and retrieve it later
Return addresses for subroutines and interrupt/exception handlers
Data to be passed to/from a subroutine/function
Stack Pointer register (r13/sp) points to last item placed on the stack
Peripheral addresses
Used to access registers in “peripheral functions” (timers, ADCs,
communication modules, etc.) outside the CPU
17
Cortex-M4 processor
memory map
Cortex peripheral function registers
(NVIC, tick timer, etc.)
(off-chip)
18
We will use Flash for code, SRAM1 for data.
Endianness
Relationship between bit and byte/word ordering defines
“endianness”:
little-endian (default) big-endian (option)
bit 31 bit 0 bit 0 bit 31
byte 3 byte 2 byte 1 byte 0 byte 0 byte 1 byte 2 byte 3
21
Directive: AREA
AREA myData, DATA, READWRITE ; Define a data section
Array DCD 1, 2, 3, 4, 5 ; Define an array with five integers
The AREA directive indicates to the assembler the start of a new data or code section.
Areas are the basic independent and indivisible unit processed by the linker.
Each area is identified by a name and areas within the same source file cannot share the same name.
An assembly program must have at least one code area.
By default, a code area can only be read and a data area may be read from and written to.
22
Directive: END
AREA myData, DATA, READWRITE ; Define a data section
Array DCD 1, 2, 3, 4, 5 ; Define an array with five integers
23
Directive: ENTRY
AREA myData, DATA, READWRITE ; Define a data section
Array DCD 1, 2, 3, 4, 5 ; Define an array with five integers
The ENTRY directive marks the first instruction to be executed within an application.
There must be one and only one entry directive in an application, no matter how many source
files the application has.
24
Directive: PROC and ENDP
AREA myData, DATA, READWRITE ; Define a data section
Array DCD 1, 2, 3, 4, 5 ; Define an array with five integers
PROC and ENDP are to mark the start and end of a function (also called subroutine or procedure).
A single source file can contain multiple subroutines, with each of them defined by a pair of PROC
and ENDP.
PROC and ENDP cannot be nested. We cannot define a subroutine within another subroutine.
25
Directive: EXPORT and IMPORT
AREA myData, DATA, READWRITE ; Define a data section
Array DCD 1, 2, 3, 4, 5 ; Define an array with five integers
The EXPORT declares a symbol and makes this symbol visible to the linker.
The IMPORT gives the assembler a symbol that is not defined locally in the current assembly file.
The IMPORT is similar to the “extern” keyword in C.
26
Directive: EQU
; Interrupt Number Definition (IRQn)
BusFault_IRQn EQU -11 ; Cortex-M3 Bus Fault Interrupt
SVCall_IRQn EQU -5 ; Cortex-M3 SV Call Interrupt
PendSV_IRQn EQU -2 ; Cortex-M3 Pend SV Interrupt
SysTick_IRQn EQU -1 ; Cortex-M3 System Tick Interrupt
MyConstant EQU 1234 ; Constant 1234 to use later
The EQU directive associates a symbolic name to a numeric constant. Similar to the use of
#define in a C program, the EQU can be used to define a constant in an assembly code.
Example:
MOV R0, #MyConstant ; Constant 1234 placed in R0
27
Directive: ALIGN
28
Directive: INCLUDE or GET
INCLUDE constants.s ; Load Constant Definitions
AREA main, CODE, READONLY
EXPORT __main
ENTRY
__main PROC
...
ENDP
END
The INCLUDE or GET directive is to include an assembly source file within another source
file.
It is useful to include constant symbols defined by using EQU and stored in a separate source
file.
29