Table of Contents
Preface ix
Chapter 1 Overview of Cortex-M3 Architecture 1
1.1 Assembly language versus the assembler 1
1.2 The world of ARM 2
1.2.1 Cortex-M3 3
1.2.2 The Cortex-M3 core in STM32 7
Chapter 2 The Core of Cortex-M3 15
2.1 Modes, privileges and states 15
2.2 Registers 17
2.2.1 Registers R0 to R12 19
2.2.2 The R13 register, also known as SP 19
2.2.3 The R14 register, also known as LR 20
2.2.4 The R15 or PC register 21
2.2.5 The xPSR register 22
Chapter 3 The Proper Use of Assembly Directives 25
3.1 The concept of the directive 25
3.1.1 Typographic conventions and use of symbols 26
3.2 Structure of a program 27
3.2.1 The AREA sections 28
3.3 A section of code 29
3.3.1 Labels 29
3.3.2 Mnemonic 31
3.3.3 Operands 32
3.3.4 Comments 34
3.3.5 Procedure 35
3.4 The data section 36
3.4.1 Simple reservation 36
3.4.2 Reservation with initialization 37
3.4.3 Data initialization: the devil is in the details 39
3.5 Is that all? 39
3.5.1 Memory management directives 40
3.5.2 Project management directives 41
3.5.3 Various and varied directives 44
Chapter 4 Operands of Instructions 47
4.1 The constant and renaming 48
4.2 Operands for common instructions 49
4.2.1 Use of registers 49
4.2.2 The immediate operand 53
4.3 Memory access operands: addressing modes 57
4.3.1 The pointer concept 58
4.3.2 Addressing modes 59
Chapter 5 Instruction Set 63
5.1 Reading guide 63
5.1.1 List of possible "condition" suffixes 65
5.2 Arithmetic instructions 66
5.3 Logical and bit manipulation instructions 70
5.4 Internal transfer instructions 75
5.5 Test instructions 76
5.6 Branch instructions 77
5.7 Load/store instructions 80
5.7.1 Simple transfers 80
5.7.2 Multiple transfers 82
5.7.3 Access to the system stack 84
5.8 "System" instructions and others 85
Chapter 6 Algorithmic and Data Structures 87
6.1 Flowchart versus algorithm 87
6.2 Alternative structures 89
6.2.1 Simple (or shortened) alternative 89
6.2.2 Complete alternative 90
6.2.3 Special case of the alternative 93
6.2.4 Multiple choice 94
6.3 Iterative structures 98
6.3.1 The Repeat...Until loop 98
6.3.2 The While...Do loop 102
6.3.3 The For ... loop 105
6.4 Compound conditions 106
6.4.1 Alternative with AND 107
6.4.2 Iteration with AND 108
6.4.3 Alternative with OR 109
6.4.4 Iteration with OR 110
6.5 Data structure 111
6.5.1 Table in one dimension 111
6.5.2 Tables in multiple dimensions 112
6.5.3 Registration 113
6.5.4 Non-dimensional table, character string 113
6.5.5 Queue 114
6.5.6 Stack 115
Chapter 7 Internal Modularity 119
7.1 Detailing the concept of procedure 119
7.1.1 Simple call 119
7.1.2 Nested calls 119
7.1.3 "Red wire" example 121
7.2 Procedure arguments 123
7.2.1 Usefulness of arguments 123
7.2.2 Arguments by value and by reference 123
7.2.3 Passing arguments by general registers 123
7.2.4 Passing arguments by a stack 126
7.2.5 Passing arguments by the system stack 133
7.2.6 On the art of mixing 136
7.3 Local data 136
7.3.1 Simple reservation of local data 137
7.3.2 Using a chained list 143
Chapter 8 Managing Exceptions 147
8.1 What happends during Reset? 148
8.2 Possible exceptions 151
8.2.1 Traps 153
8.2.2 Interrupts 159
8.3 Priority management 161
8.3.1 Priority levels and sublevels 162
8.3.2 The nested mechanism 166
8.4 Entry and return in exception processing 167
8.4.1 Re-routing 167
8.4.2 Return 169
8.4.3 "Tail-chaining" and "Late-arriving" 169
8.4.4 Other useful registers for the NVIC 170
Chapter 9 From Listing to Executable: External Modularity 173
9.1 External modularity 175
9.1.1 Generic example 175
9.1.2 Assembly by pieces 178
9.1.3 Advantages of assembly by pieces 178
9.1.4 External symbols 179
9.1.5 IMPORT and EXPORT directives 181
9.2 The role of the assembler 182
9.2.1 Files produced by the assembler 183
9.2.2 Placement counters 185
9.2.3 First pass: symbol table 185
9.2.4 Second pass: translation 186
9.2.5 Relocation table 187
9.3 The role of the linker 188
9.3.1 Functioning principle 188
9.3.2 The products of the linker 190
9.4 The loader and the debugging unit 196
Appendices 199
Appendix A Instruction Set - Alphabetical List 201
Appendix B The SysTick Timer 209
Appendix C Example of a "Bootstrap" File 217
Appendix D The GNU Assembler 227
Bibliography 239
Index 241