Basics of Assembly Programming: Microprocessor Systems
Basics of Assembly Programming: Microprocessor Systems
Microprocessor Systems
Contents
3 Reset Sequence
4 Instruction Encoding
2/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Introduction
3/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Thumb 2
4/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Cont’d:
16-bit Thumb 32-bit Thumb2 16-bit Thumb 16-bit Thumb 32-bit Thumb2
5/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
6/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
7/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Thumb2
Instruction Set
Memory Access
Instructions Data Processing
Instructions
Saturating Instructions
Cortex-M3,
Branch & Control M4 and M4F
Instructions
Floating Point Cortex-M4
Instructions and M4F
8/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Add Instruction
9/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
10/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Branch Instructions
11/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Example Program
12/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
lbegin
CBZ R2 , lend ; If R2 != 0 continue with the next
; instruction
ADD R0 , R1
ADD R1 , #2
SUB R2 , #1
B lbegin ; branch unconditionally to lbegin
lend
Listing 4: A simple program calculating the sum of the first five even
numbers.
13/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
14/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Assember Directives
15/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
• AREA
• Size Directives: SPACE, DCB, DCW, DCD
• EQU: Symbolic name to a numeric constant
• ENTRY: Declares an entry point to a program
• END: Informs the assembler that it has reached the end of a
source file
16/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
17/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
AREA Directive
18/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
19/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Attribute Description
READONLY Indicates that this section must not be written to. This is the default
for code areas.
NOINIT Use of this attribute indicates that the data section is uninitialized, or
initialized to zero. A section with this attribute contains only space
reservation directives SPACE or DCB, DCD, DCDU, DCQ, DCQU,
DCW, or DCWU with initialized values of zero. You can decide at link
time whether an area is uninitialized or zero initialized.
READWRITE Indicates that this section can be read from and written to. This is
the default for Data areas.
DATA Contains data, not instructions. READWRITE is the default.
CODE Contains machine instructions. READONLY is the default.
ALIGN=number By default, sections are aligned on a four-byte boundary. The number
can have any integer value from 0 to 31. The section is aligned on a
2number byte boundary. For example, if expression is 10, the section is
aligned on a 1 KB boundary.
20/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
21/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Reset Sequence
Stack Pointer Reset Address System User Program
Loaded Loaded to PC Initialization Execution
Time
22/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Memory Map
Other Memory (RAM) Initialization of SP
to 0x20008000
0x20008000
1st Stacked Item
0x20007FFC
2nd Stacked Item
0x20007FF8
Stack
.
. Memory
.
0x20007C00
Last possible stacked item Stack grows
Reset sequence of downward
0x20000000
to memory address
map. Other Memory (FLASH)
Reset Vector
Loading
System Initialization Code
0x00000100
24/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
lbegin
CBZ R2 , lend ; Terminate loop if counter is zero
ADD R0 , R1 ; Build the sum
ADD R1 , #2 ; Generate next even number
SUB R2 , #1 ; Decrement the counter
B lbegin
lend
END
25/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
26/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
27/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Lbegin
CBZ R4 , Lend
ADD R5 , R3
SUB R4 , #1
B Lbegin
Lend
STR R5 , [ R2 ] ; store the product back to PRODUCT
ALIGN
END ; End of program , matched with ENTRY
28/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
Instruction Encoding
29/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
30/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
31/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
31/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
32/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
32/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
33/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
33/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
33/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
See article 5.1.2 of text book and Articles 3.3.1 and 4.2 of ARM
Architecture Reference Manual Thumb-2 Supplement
34/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
35/36
Assembly Language Introduction Selected Assembly Instructions Reset Sequence Instruction Encoding
36/36