ARM Assembly for Embedded Applications, 3rd Edition

ARM Assembly for Embedded Applications, 3rd Edition

by Daniel W. Lewis

Paperback

$49.95
Choose Expedited Shipping at checkout for guaranteed delivery by Tuesday, September 24

Overview

ARM Assembly for Embedded Applications is a text for a sophomore-level course in computer science, computer engineering, or electrical engineering that teaches students how to write functions in ARM assembly called by a C program. The C/Assembly interface (i.e., function call, parameter passing, return values, register conventions) is presented early so that students can write simple functions in assembly as soon as possible. The text then covers the details of arithmetic, bit manipulation, making decisions, loops, integer arithmetic, real arithmetic floating-point and fixed-point representations, inline coding and I/O programming.

What’s new: This 3rd edition adds two new chapters. Chapter 11 is on multimedia processing, with several examples that use the saturating arithmetic and SIMD (Single Instruction Multiple Data) instructions of the ARM processor to implement fast routines for multimedia applications. Chapter 12 uses the SIMD instructions to implement functions for rational and complex arithmetic. The material on bit manipulation instructions has been updated with a discussion of how to use the basic operations of AND, OR and exclusive-OR as filters that pass a bit unmodified to the output, force it to either 0 or 1, or change it to the opposite of its previous value. New illustrations show how it is sometimes easier to translate for and while loops into assembly by first converting them into an arrangement of goto statements, statement labels, and an inverted test for completion. There are additional examples of how to implement multiplication and division by a constant more efficiently than using multiply and divide instructions, with a C program added to the textbook website that generates fast instruction sequences for division by a constant. New illustrations clarify the algorithm for multiplying fixed-point reals, and there is new material on instruction cycle counts, pipeline stalls, execution time measurement, memory-mapped I/O ports, data rates and synchronization.

Product Details

ISBN-13: 9781543908046
Publisher: BookBaby
Publication date: 09/07/2017
Pages: 318
Product dimensions: 6.00(w) x 9.00(h) x 0.90(d)

About the Author

Dan Lewis has been a tenure-track faculty member at Santa Clara University since 1975. In 1988, his efforts led to the creation of the Computer Engineering department, and he served as its first department chair for the first 18 years. Prior to joining the University, Lewis worked for six years at General Electric's Aerospace Division where he developed a fault-tolerant clocking system for one of the first triple-redundant automatic landing systems for commercial aircraft. He has provided hardware and software consulting services for a number of Silicon Valley companies, worked extensively to improve K-12 education in computer science, and is the author of three textbooks on embedded software.

Table of Contents

Preface vii

Chapter 1 Introduction 1

1.1 Why You Should Learn Assembly 2

1.2 When Assembly is Needed 4

1.3 What Assembly Language Looks Like 7

1.4 How Assemblers Work 9

1.5 Integer Data types Used in this Book 11

1.6 Identifier Conventions Used in this Book 12

Chapter 2 Binary Number Systems 15

2.1 Converting Unsigned Binary to Decimal 16

2.2 Converting Unsigned Decimal to Binary 17

2.2.1 Method #1a: Converting the whole port 17

2.2.2 Method #1b: Converting the fractional part 18

2.2.3 Method #2: Starting with the largest k such that 2k ≤ N 19

2.3 Signed 2's Complement Integers 20

2.3.1 Converting Decimal to Two's Complement 23

2.3.2 Converting Two's Complement to Decimal 24

2.4 Hex as a Shorthand for Binary 24

Problems 26

Chapter 3 Writing Functions in Assembly 31

3.1 Instruction Sequencing 31

3.2 Function Call and Return 32

3.3 Function Parameters 36

3.4 Function Return Value 38

3.5 Register Usage Conventions 40

3.6 Function Coding Conventions 43

Problems 44

Chapter 4 Copying Data 47

4.1 Constant and Expression Syntax 47

4.2 Copying Constants into Registers 48

4.3 Copying Data from Memory to Registers 50

4.3.1 Zero-Extending 8 and 16-bit Unsigned Integers 52

4.3.2 Zero-Extending 32-Bit Unsigned Values to 64-Bits 52

4.3.3 Sign-Extending 8 and 16-Bit 2's Complement Integers 53

4.3.4 Sign-Extending 32-Bit 2's Complement Integers to 64-Bits 53

4.4 Copying Data from One Register to Another 54

4.5 Copying Data from Registers to Memory 54

4.6 Examples of Copying Data 56

4.7 Addressing Modes 56

4.8 Pointers and Arrays 60

4.9 Pointers and Structures 63

4.10 Copying a Block of Data Quickly 65

Problems 68

Chapter 5 Integer Arithmetic 73

5.1 Condition Flags 73

5.2 Addition and Subtraction 74

5.2.1 Carries and Overflow 76

5.2.2 Multiple Precision 77

5.3 Multiplication 78

5.3.1 Signed versus Unsigned Products 79

5.3.2 64x64 Single-Length Products 81

5.3.3 Multiplication Overflow 83

5.4 Division 83

5.4.1 Signed versus Unsigned 84

5.4.2 Division Overflow 84

5.4.3 Calculating a Remainder 85

Problems 86

Chapter 6 Making Decisions and Writing Loops 89

6.1 Compare and Test Instructions 89

6.2 Conditional Branch Instructions 90

6.3 If-Then-Else Sequences 93

6.4 Comparing 64-Bit Integers 95

6.5 It Blocks 96

6.6 Compound Conditionals 99

6.7 Writing Loops 103

Problems 107

Chapter 7 Manipulating Bits 111

7.1 Basic Shift Operations 111

7.1.1 Pre-Shifting Operands 114

7.1.2 Regular Shift instructions 115

7.1.3 Multiple Precision Shifts 116

7.2 Bitwise Instructions 118

7.3 Bitfield Instructions 122

7.4 Miscellaneous Bit Manipulation Instructions 127

7.5 Bit-Banding 127

Problems 131

Chapter 8 Multiplication and Division Revisited 133

8.1 Multiplication by a Constant 134

8.1.1 Constant Multiplication Using a Single Instruction 134

8.1.2 Constant Multiplication Using Multiple Instructions 135

8.2 Division by a Power of Two 137

8.3 Division by an Arbitrary Constant 139

8.4 Remainder When Dividing by 2K 143

8.5 Calculating True Modulus with Arbitrary Divisor 145

8.6 Measuring Execution Time 146

Problems 148

Chapter 9 Getting Started with Floating Point 151

9.1 Data Types for Real Numbers 151

9.2 Floating-Point Registers 153

9.3 Function Parameters and Return Values 155

9.4 Copying Data 155

9.4.1 Copying a Constant into a Register 156

9.4.2 Copying One Register to Another 158

9.4.3 Copying from Memory to a Register 159

9.4.4 Copying from a Register to Memory 160

9.5 Converting Between Integers and Floating Point Reals 162

9.6 Arithmetic with Real Numbers 164

9.7 Comparing Real Numbers 166

9.8 FPU Instruction Timing 169

Problems 172

Chapter 10 Working with Fixed-Point Real Numbers 175

10.1 Q Format and the Imaginary Binary Point 176

10.2 Addition and Subtraction of Fixed-Point Reals 178

10.3 Multiplication and Division of Fixed-Point Reals 179

10.4 Fixed-Point Using a Universal Q16.16 Format 181

10.5 Multiplication of Q32.32 Fixed-Point Reals 184

10.5.1 The 128-bit Product of Two 64-bit Unsigned Integers 185

10.5.2 Converting a Product from Unsigned to 2's Complement 186

10.5.3 Example: Multiplying two Q4.4 Fixed-Point Reals 188

10.5.4 Implementation of Q32.32 Multiplication in Assembly 190

10.6 Division of Q32.32 Fixed-Point Reals 192

10.7 Programming with Q32.32 Reals 196

Problems 198

Chapter 11 Multimedia Processing 201

11.1 SIMD Processing 202

11.1.1 SIMD Example: Color Negative of an Image 202

11.1.2 SIMD Add and Subtract Instructions 204

11.1.3 SIMD Example: Minimums and Maximums 205

11.1.4 SIMD Multiply Instructions 207

11.1.5 SIMD Example: Dot Product 208

11.1.6 SIMD Example: FIR Smoothing Filter 210

11.2 Saturation Processing 213

11.2.1 SIMD Saturating Add and Subtract Instructions 214

11.2.2 SIMD Saturating Example: Brightness Adjustment 214

11.3 Multimedia Flags 215

Problems 217

Chapter 12 Rational and Complex Arithmetic 219

12.1 Data Type Representation 219

12.2 Rational Numbers 221

12.2.1 Arithmetic with Rational Numbers 223

12.2.2 Simplifying Rational Numbers 225

12.2.3 An Example Program Using Rational Numbers 226

12.3 Complex Numbers 227

12.3.1 Arithmetic with Complex Numbers 229

12.3.2 Programming with Complex Numbers 229

12.3.3 An Example Program Using Complex Numbers 232

Problems 234

Chapter 13 Inline Code 237

13.1 Inline Functions 237

13.2 Inline Assembly 238

13.2.1 Input and Output Operands 240

13.2.2 Operand Constraints 242

13.2.3 Allowing Constants or Registers as Operands 243

13.2.4 Constraint Modifiers 243

13.2.5 The Clobbers Component 245

13.2.6 Working with 64-bit Operands 247

13.2.7 Statement Labels 247

13.2.8 The Optional Volatile Keyword 248

13.2.9 Using Artificial Dependencies 249

13.3 Combining Inline Functions and Inline Assembly 251

Problems 253

Chapter 14 Programming Peripheral Devices 255

14.1 Device Data, Control and Status 256

14.2 Memory-Mapped Input/Output 258

14.3 Data Rates and Synchronization 259

14.4 Blocking I/O: CRC32 Peripheral 260

14.4.1 The Basic CRC Algorithm 260

14.4.2 A Hardware-Assisted Implementation in C 262

14.4.3 A Hardware-Assisted Implementation in Assembly 264

14.5 Polled Waiting Loop: Random Number Generator 266

14.6 Interrupt-Driven: Timer Tick 269

14.7 Direct-Memory Access: Memory-To-Memory Transfer 275

14.8 The CPU Clock Cycle Counter 277

Problems 278

Appendix A The STM32F429I Discovery Board 281

Appendix B Basic Support Library 283

Appendix C Graphics Library 285

Appendix D Touch Screen Library 287

Appendix E Creating an Embitz Project the Easy Way 289

Appendix F Creating an Embitz Project from Scratch 295

Index 301

Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews