The Microprocessor - Darshak S. Vasavada - E-Book

The Microprocessor E-Book

Darshak S. Vasavada

0,0
83,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

Provides a comprehensive introduction to microprocessor architecture and programming concepts, using the Arm® Cortex®-M0 processor as an example

The Microprocessor offers a supremely accessible and user-friendly introduction to microprocessor basics: instruction set, the exception model, system architecture and microcontroller programming. Explaining the working principles with simplified models, this first-level book builds the base for all onward courses at intermediate and advanced levels.

Filled with exercises that can be executed on the free version of Keil® μVision® MDK without any hardware, the book explains the essential aspects of microprocessor architecture with simple programming examples in assembly and C. By blending conceptual knowledge with practical exercises, the book offers valuable insights that equip readers to engage with real-world applications in the fields of microprocessor architecture and embedded systems.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 785

Veröffentlichungsjahr: 2025

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Cover

Table of Contents

Title Page

Copyright

List of Exercises

Preface

About This Book

How to Read This Book

Acknowledgements

About the Companion Website

Introduction

1 MICROPROCESSOR SYSTEM

2 MICROCONTROLLER PROCESSORS

3 REAL-TIME PROCESSORS

4 APPLICATION PROCESSORS

5 OVERVIEW OF ARM CORTEX PROCESSORS

CHAPTER 1: Microprocessor System

1.1 INTRODUCTION

1.2 PROCESSOR

1.3 MEMORY

1.4 MEMORY DEVICES

1.5 BUS

1.6 IO PORTS

1.7 RESET, CLOCK AND POWER MANAGEMENT

1.8 OVERVIEW OF ARM CORTEX-M0 PROCESSOR

1.9 SUMMARY

CHAPTER 2: Instruction Set Architecture

2.1 INTRODUCTION

2.2 REGISTERS

2.3 INSTRUCTION SET

2.4 STRUCTURE OF AN INSTRUCTION

2.5 DATA-PROCESSING INSTRUCTIONS

2.6 MEMORY-ACCESS INSTRUCTIONS

2.7 PROGRAM-CONTROL INSTRUCTIONS

2.8 SUMMARY

CHAPTER 3: Program Execution

3.1 INTRODUCTION

3.2 PROGRAM

3.3 INSIDE THE CPU

3.4 FETCH UNIT

3.5 DECODE UNIT

3.6 EXECUTION UNIT

3.7 INSTRUCTION EXECUTION

3.8 PROCESSOR PIPELINE

3.9 SUMMARY

CHAPTER 4: Assembly Programming

4.1 STATEMENTS

4.2 LABELS

4.3 SECTIONS

4.4 TEXT SECTION

4.5 DATA SECTIONS

4.6 SUMMARY

CHAPTER 5: Arithmetic Operations

5.1 ARITHMETIC INSTRUCTIONS

5.2 UNSIGNED INTEGERS

5.3 SIGNED INTEGERS

5.4 APSR FLAGS

5.5 CONDITION CODES

5.6 SUMMARY

CHAPTER 6: Bit-Level Operations

6.1 BOOLEAN INSTRUCTIONS

6.2 BIT MANIPULATION

6.3 SHIFT OPERATIONS

6.4 WORD-LENGTH EXTENSION

6.5 BYTE ORDERING INSTRUCTIONS

6.6 SUMMARY

CHAPTER 7: Load and Store Operations

7.1 INTRODUCTION

7.2 ALIGNMENT

7.3 ENDIANNESS

7.4 BASIC LOAD AND STORE OPERATIONS

7.5 DATA TYPES

7.6 OFFSET ADDRESSING

7.7 SUMMARY

CHAPTER 8: Branch and Subroutine

8.1 PROGRAM-CONTROL INSTRUCTIONS

8.2 BRANCH

8.3 CONDITIONAL BRANCH

8.4 INDIRECT BRANCH

8.5 SUBROUTINES

8.6 NESTED SUBROUTINES

8.7 SUMMARY

CHAPTER 9: Stack Operations

9.1 INTRODUCTION

9.2 WHAT IS A STACK?

9.3 STACK IN CORTEX-M0

9.4 STACK OPERATIONS

9.5 CREATING A STACK

9.6 USING THE STACK

9.7 LOCAL VARIABLES

9.8 SUMMARY

CHAPTER 10: Exceptions

10.1 INTRODUCTION

10.2 EXCEPTION MODEL

10.3 VECTOR TABLE

10.4 RESET

10.5 FAULTS

10.6 EXCEPTION STACK FRAME

10.7 SUMMARY

CHAPTER 11: SysTick and Core Interrupts

11.1 INTRODUCTION

11.2 SYSTICK

11.3 SYSTICK PROGRAMMING MODEL

11.4 PROGRAMMING SYSTICK

11.5 USING SYSTICK

11.6 POLLING WITH SYSTICK

11.7 SYSTICK INTERRUPTS

11.8 INTERRUPT MASKING

11.9 NON-MASKABLE INTERRUPT (NMI)

11.10 SUMMARY

CHAPTER 12: Introduction to C Programming

12.1 PROGRAMMING LANGUAGES

12.2 STRUCTURE OF A C PROGRAM

12.3 FUNCTIONS

12.4 DATA

12.5 HEADER FILES

12.6 OVERVIEW OF C LANGUAGE

12.7 SUMMARY

CHAPTER 13: Basic Data Types

13.1 CHARACTERS AND STRINGS

13.2 INTEGERS

13.3 FLOATING-POINT NUMBERS

13.4 FLOATING-POINT OPERATIONS

13.5 TYPE-CASTING

13.6 SUMMARY

CHAPTER 14: Functions

14.1 FUNCTION CALLS

14.2 ARGUMENTS

14.3 LOCAL VARIABLES

14.4 CONDITIONAL EXECUTION

14.5 SELECTION

14.6 LOOPS

14.7 SUMMARY

CHAPTER 15: Extended Data Types

15.1 ARRAYS

15.2 STRUCTURES

15.3 POINTERS

15.4 ARRAYS AND POINTERS

15.5 POINTER TO A STRUCTURE

15.6 POINTER ARITHMETIC

15.7 UNINITIALIZED POINTERS

15.8 SUMMARY

CHAPTER 16: Compilation Process

16.1 OVERVIEW OF THE COMPILATION PROCESS

16.2 PREPROCESSING

16.3 COMPILATION

16.4 ASSEMBLER

16.5 LINKER

16.6 EXECUTABLE PROGRAM

16.7 SUMMARY

CHAPTER 17: Microcontroller

17.1 INTRODUCTION

17.2 BLOCK DIAGRAM

17.3 PIN DIAGRAM

17.4 RESET, CLOCK AND POWER MANAGEMENT

17.5 PERIPHERAL INTERRUPTS

17.6 PERIPHERAL REGISTERS

17.7 PERIPHERAL API

17.8 SUMMARY

CHAPTER 18: IO Programming

18.1 IO DEVICES

18.2 GPIO

18.3 TIMER

18.4 ADC

18.5 DAC

18.6 UART

18.7 INTERRUPTS

18.8 SUMMARY

CHAPTER 19: Microprocessor Applications

19.1 LED BRIGHTNESS CONTROLLER

19.2 AMBIENT LIGHT SENSOR

19.3 ENERGY-EFFICIENT CODING

19.4 TEMPERATURE MONITORING

19.5 MOTOR SPEED CONTROL

19.6 SUMMARY

APPENDIX A: Programming Environment

A.1 INTRODUCTION

A.2 KEIL MDK

A.3 ASSEMBLY PROGRAMMING SETUP

A.4 WRITING AND BUILDING ASSEMBLY PROGRAMS

A.5 DEBUGGING AN ASSEMBLY PROGRAM

A.6 C PROGRAMMING SETUP

A.7 WRITING AND BUILDING C PROGRAM

A.8 DEBUGGING A C PROGRAM

A.9 DEBUGGER

APPENDIX B: Advanced Topics

B.1 SYSTEM-CONTROL INSTRUCTIONS

B.2 OS SUPPORT

APPENDIX C: Startup Code

C.1 OS-LESS SYSTEM

C.2 STARTUP CODE

C.3 LINKER SCRIPT FILE

APPENDIX D: AM0 Header Files

D.1 REGISTER HEADER FILE

D.2 AM0 HEADER FILE

Glossary of Acronyms

References

Index

End User License Agreement

List of Illustrations

How to Read This Book

Figure 1 Chapter map.

Introduction

Figure I.1 A simplified microprocessor system

Chapter 1

Figure 1.1 A simple microprocessor system.

Figure 1.2 Information stored in a byte.

Figure 1.3 Information stored in 2 bytes.

Figure 1.4 Addressing memory devices.

Figure 1.5 A simplified bus.

Figure 1.6 An IO port.

Figure 1.7 Inside an IO port.

Figure 1.8 Interrupt request.

Figure 1.9 Cortex-M0 processor.

Figure 1.10 Memory map defined by Armv6-M architecture.

Chapter 2

Figure 2.1 Cortex-M0 registers.

Figure 2.2 Cortex-M0 instruction classification.

Figure 2.3 Structure of a 2-operand instruction code.

Figure 2.4 Instruction code for ADD instruction.

Chapter 3

Figure 3.1 An example program stored in memory.

Figure 3.2 Microprocessor block diagram.

Figure 3.3 Execution unit.

Figure 3.4 Fetch unit.

Figure 3.5 Decode unit.

Figure 3.6 Decoding data-processing instructions.

Figure 3.7 Decoding load-store instructions.

Figure 3.8 Execution unit.

Figure 3.9 Arithmetic logic unit.

Figure 3.10 Load-store unit

Figure 3.11 Decoding MUL instruction.

Figure 3.12 Executing MUL instruction.

Figure 3.13 LDR encoding.

Figure 3.14 Executing LDR instruction.

Figure 3.15 Sequential execution of instructions.

Figure 3.16 Pipelined execution of instructions.

Figure 3.17 Processor pipeline.

Chapter 4

Figure 4.1 Sections of an assembly program.

Figure 4.2 A code section.

Figure 4.3 Disassembly and Source Windows showing program is ready to run.

Figure 4.4 A data section.

Chapter 5

Figure 5.1

APSR flags

.

Chapter 6

Figure 6.1 Logical shift.

Figure 6.2 Arithmetic shift right.

Figure 6.3 Rotate right operation.

Figure 6.4 Zero-extension.

Figure 6.5 Sign extension.

Chapter 7

Figure 7.1 Byte, half-word and word stored at address

A

.

Figure 7.2 Memory Window showing alignment of half-word and word.

Figure 7.3 Storing multiple bytes in multiple locations: in which order?

Figure 7.4 Little-endian and big-endian byte ordering for storing a 4-byte w...

Figure 7.5 Little-endian and big-endian byte ordering for storing a 2-byte h...

Figure 7.6 Memory Window showing data stored in little-endian and big-endian...

Figure 7.7 Loading unsigned half-word and byte.

Figure 7.8 Loading signed half-word and byte.

Figure 7.9 Effective address for loading a byte.

Figure 7.10 Effective address for loading a half-word or a word.

Figure 7.11 PC-relative addressing for constants stored in the literal pool....

Chapter 8

Figure 8.1 Branch operation.

Figure 8.2 Subroutine.

Figure 8.3 Registers used by a subroutine.

Chapter 9

Figure 9.1 Nested subroutines.

Figure 9.2 Use of memory in nested subroutines.

Figure 9.3 Push and pop operations on a stack of books.

Figure 9.4 Push and pop operations on a stack in memory.

Figure 9.5 Push and pop operations on a stack in RAM.

Figure 9.6 Bottom-to-top and top-to-bottom way of drawing stack.

Figure 9.7 Memory Window showing initial stack pointer at reset.

Figure 9.8 PUSH instruction execution.

Figure 9.9 POP instruction execution.

Figure 9.10 Use of registers in a subroutine.

Figure 9.11 A subroutine overwriting the return address in LR.

Figure 9.12 Allocating and freeing memory on the stack.

Figure 9.13 Stack frame.

Chapter 10

Figure 10.1 Program execution on an exception.

Figure 10.2 Exception vector table for Cortex-M0 processor.

Figure 10.3 Memory Window showing the vector table.

Figure 10.4 Exception handlers in Disassembly Window.

Figure 10.5 Exception stack frame.

Figure 10.6 Exception handler interrupting the normal code.

Figure 10.7 Memory Window showing the registers stored in the stack frame.

Figure 10.8 Program Status Register.

Chapter 11

Figure 11.1 SysTick operation.

Figure 11.2 SysTick Current Value Register (

SYST_CVR

).

Figure 11.3 SysTick Reload Value Register (

SYST_RVR

).

Figure 11.4 SysTick Control and Status Register (

SYST_CSR

).

Figure 11.5 PRIMASK register.

Chapter 12

Figure 12.1 Local variables in Call Stack Window.

Figure 12.2 Value of

f

computed by

c2f

function at the end of the program.

Figure 12.3 Call Stack Window showing incorrect value of

f

.

Figure 12.4 Call Stack Window showing incorrect value of

c

.

Figure 12.5 Memory Window showing value of c in decimal and floating-point f...

Figure 12.6 Call Stack Window showing value of

c

corrected to 40.

Figure 12.7 Call Stack Window showing correct values of

c

and

f

.

Chapter 13

Figure 13.1 µVision screen-shot showing characters inside Memory Window.

Figure 13.2 µVision screen-shot showing strings inside Memory Window.

Figure 13.3 Memory Window showing strings stored as a sequence of bytes.

Figure 13.4 Memory Window showing an unsigned char type in decimal format.

Figure 13.5 Memory Window showing

short

and

int

data types.

Figure 13.6 Endianness and alignment.

Figure 13.7 Signed and unsigned data in hexadecimal and decimal formats.

Figure 13.8 Floating-point numbers in “Float” format and hexadecimal represe...

Figure 13.9 Watch Window showing values in mixed hex and float format.

Chapter 14

Figure 14.1 Implementation of a function call.

Figure 14.2 Local variables on the stack.

Chapter 15

Figure 15.1 Memory Window showing const, initialized and uninitialized array...

Figure 15.2 Memory Window showing

a[]

and initial values of

b[]

.

Figure 15.3 Memory Window showing padding between structure elements.

Figure 15.4 Memory Window showing elements of a packed structure without pad...

Figure 15.5 Memory Window showing a pointer containing the address of anothe...

Figure 15.6 Memory Window showing a pointer pointing to an array.

Figure 15.7 Meaning of

p+1

for pointers to various types of data types....

Figure 15.8 Memory Window showing the array and pointer values at the end of...

Figure 15.9 Watch Window showing a NULL pointer getting the vector table con...

Figure 15.10 Memory Window showing the stack.

Chapter 16

Figure 16.1 Preprocessing, compilation and assembly.

Figure 16.2 Linking process.

Figure 16.3 Classification of statements in C.

Figure 16.4 Compilation and assembly process.

Figure 16.5 Translation process by the assembler.

Figure 16.6 Section placement.

Figure 16.7 A symbol getting its address in two steps.

Figure 16.8 Executable in simplified ELF format.

Chapter 17

Figure 17.1 AM0 microcontroller block diagram.

Figure 17.2 AM0 pin diagram.

Figure 17.3 Reset, clock and power management unit.

Figure 17.4 AM0 clock tree.

Figure 17.5 Peripheral interrupts connected to CPU.

Figure 17.6 Peripheral registers.

Figure 17.7 Memory-mapping peripheral registers.

Figure 17.8 Example peripheral register definition.

Chapter 18

Figure 18.1 Example system with multiple IO devices.

Figure 18.2 GPIO port example with P0 as input and P1 as output.

Figure 18.3 Interfacing an LED and a push-button switch.

Figure 18.4 ADC converting analog voltage into a digit.

Figure 18.5 Interfacing an analog signal.

Figure 18.6 DAC converting a digit written by CPU to an analog voltage.

Figure 18.7 Sine wave generated using a DAC.

Figure 18.8 Exchanging data with a remote device.

Figure 18.9 UART over USB.

Chapter 19

Figure 19.1 Automatic LED control with ambient light sensing.

Figure 19.2 Timer interrupt for LED brightness control.

Figure 19.3 Interfacing a DC motor and a rotary encoder.

Figure 19.4 Input voltage at P1 indicating the presence of slots in the enco...

Appendix A

Figure A.1 Programming environment.

Figure A.2 Programming exercises workflow.

Figure A.3 (a) Linker settings, (b) Debugger configuration.

Figure A.4 Source code to executable program.

Figure A.5 Program image.

Figure A.6 Register Window.

Figure A.7 Source Window showing assembly source code.

Figure A.8 Disassembly Window.

Figure A.9 Memory Windows displaying content as Unsigned Long.

Figure A.10 Source code to executable program.

Figure A.11 Source Window showing C source code.

Figure A.12 Disassembly Window.

Figure A.13 Watch Window showing global variables.

Figure A.14 Debugger.

Appendix C

Figure C.1

Software components of a OS-less system

Guide

Cover

Table of Contents

Title Page

Copyright

List of Exercises

Preface

About This Book

How to Read This Book

Acknowledgements

About the Companion Website

Introduction

Begin Reading

Appendix A: Programming Environment

Appendix B: Advanced Topics

Appendix C: Startup Code

Appendix D: AM0 Header Files

Glossary of Acronyms

References

Index

End User License Agreement

Pages

iii

iv

x

xi

xii

xiii

xv

xvi

xvii

xviii

xix

xxi

xxii

xxiii

xxiv

xxv

xxvi

xxvii

xxviii

xxix

xxx

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

475

476

477

478

479

480

481

482

483

484

485

487

488

489

491

492

493

494

495

496

497

498

499

The Microprocessor

A Practical Introduction using the Arm® Cortex®-M0 Processor

 

 

Darshak S. Vasavada

Robert Bosch Center for Cyber-Physical Systems, Indian Institute of Science, Bangaluru, India

S. K. Sinha

Lab To Market Innovations Private Limited, FSID, IISc, Bangaluru, India

 

 

 

 

 

 

 

 

This Work is a co-publication between Arm Education and John Wiley & Sons, Inc.

Copyright © 2025 by John Wiley & Sons Inc. All rights reserved, including rights for text and data mining and training of artificial technologies or similar technologies.

Published by John Wiley & Sons, Inc., Hoboken, New Jersey.Published simultaneously in Canada.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permission.

Any source code, models or other materials set out in this book should only be used for non-commercial, educational purposes (and/or subject to the terms of any license that is specified or otherwise provided by Arm). In no event shall purchasing this book be construed as granting a license to use any other Arm technology or know-how.

The manufacturer's authorized representative according to the EU General Product Safety Regulation is Wiley-VCH GmbH, Boschstr. 12, 69469 Weinheim, Germany, e-mail: [email protected].

Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United States and other countries and may not be used without written permission. The Arm corporate logo and words marked with ® or ™ are registered trademarks or trademarks of Arm Limited (or its subsidiaries or affiliates) in the US and/or elsewhere. All rights reserved. For more information about Arm's trademarks, please visit https://www.arm.com/company/policies/trademarks. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.

Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages. Further, readers should be aware that websites listed in this work may have changed or disappeared between when this work was written and when it is read. Neither the publisher nor authors shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages.

For general information on our other products and services or for technical support, please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic formats. For more information about Wiley products, visit our website at www.wiley.com.

Library of Congress Cataloging-in-Publication Data:

Names: Vasavada, Darshak S., author. | Sinha, Sudhir Kumar, author.

Title: The microprocessor : a practical introduction using the Arm   Cortex-M0 processor / Darshak S. Vasavada, S. K. Sinha.

Description: Hoboken, NJ : Wiley, 2025. | Includes bibliographical   references and index.

Identifiers: LCCN 2024037432 (print) | LCCN 2024037433 (ebook) | ISBN   9781394245291 (hardback) | ISBN 9781394245314 (adobe pdf) | ISBN   9781394245307 (epub)

Subjects: LCSH: Microprocessors.

Classification: LCC TK7895.M5 V37 2025 (print) | LCC TK7895.M5 (ebook) |   DDC 004.16–dc23/eng/20240923

LC record available at https://lccn.loc.gov/2024037432

LC ebook record available at https://lccn.loc.gov/2024037433

Cover Design: WileyCover Image: © sankai/Getty Images

List of Exercises

EXERCISE 4.0

   Create a new project

EXERCISE 4.1

   My first assembly program

EXERCISE 4.2

   Exploring the instruction codes

EXERCISE 4.3

   Accessing data from the memory

EXERCISE 5.0

   Create a new project

EXERCISE 5.1

   Addition

EXERCISE 5.2

   Multiplication

EXERCISE 5.3

   Subtraction

EXERCISE 5.4

   N and Z bits

EXERCISE 5.5

   Carry and overflow

EXERCISE 5.6

   Unsigned comparison

EXERCISE 5.7

   Signed comparison

EXERCISE 6.0

   Create a new project

EXERCISE 6.1

   Boolean operations

EXERCISE 6.2

   Setting, clearing and testing bits

EXERCISE 6.3

   Logical shift

EXERCISE 6.4

   Arithmetic shift

EXERCISE 6.5

   Word-length extension

EXERCISE 7.0

   Create a new project

EXERCISE 7.1

   Data formats

EXERCISE 7.2

   Endianness

EXERCISE 7.3

   Basic load and store

EXERCISE 7.4

   Sign extension

EXERCISE 7.5

   Immediate offset

EXERCISE 7.6

   Register offset

EXERCISE 8.0

   Create a new project

EXERCISE 8.1

   Jumping around

EXERCISE 8.2

   

if-else

statements

EXERCISE 8.3

   Loops

EXERCISE 8.4

   Selection

EXERCISE 8.5

   Subroutine

EXERCISE 8.6

   Registers used in a subroutine

EXERCISE 9.0

   Create a new project

EXERCISE 9.1

   Where is the stack?

EXERCISE 9.2

   Push and pop

EXERCISE 9.3

   Registers on stack

EXERCISE 9.4

   Nested subroutines

EXERCISE 9.5

   Local variables on the stack

EXERCISE 10.1

   Vector table

EXERCISE 10.2

   Startup and main code

EXERCISE 10.3

   HardFault

EXERCISE 10.4

   Exception stack frame

EXERCISE 11.1

   SysTick in action

EXERCISE 11.2

   Polling with SysTick

EXERCISE 11.3

   SysTick with interrupt

EXERCISE 11.4

   Masking SysTick

EXERCISE 11.5

   NMI

EXERCISE 12.0

   Create a new project

EXERCISE 12.1

   Function call

EXERCISE 12.2

   Global variables

EXERCISE 12.3

   Local variables

EXERCISE 12.4

   Function declaration

EXERCISE 12.5

   Header file

EXERCISE 13.0

   Create a new project

EXERCISE 13.1

   Characters

EXERCISE 13.2

   Strings

EXERCISE 13.3

   Integer data type

EXERCISE 13.4

   Endianness and alignment

EXERCISE 13.5

   Addition

EXERCISE 13.6

   Sign and word-length

EXERCISE 13.7

   Floating-point representation

EXERCISE 13.8

   Floating-point addition

EXERCISE 13.9

   Type-casting

EXERCISE 14.0

   Create a new project

EXERCISE 14.1

   Function call

EXERCISE 14.2

   Arguments in registers

EXERCISE 14.3

   Local variables

EXERCISE 14.4

   Conditional execution

EXERCISE 14.5

   

switch-case

statement

EXERCISE 14.6

   

for

loop

EXERCISE 15.0

   Create a new project

EXERCISE 15.1

   Arrays

EXERCISE 15.2

   Implementation of a structure

EXERCISE 15.3

   Pointer as a fixed address

EXERCISE 15.4

   Pointers

EXERCISE 15.5

   Arrays and pointers

EXERCISE 15.6

   Pointer to a structure

EXERCISE 15.7

   Pointer arithmetic

EXERCISE 15.8

   Accessing

NULL

pointer

EXERCISE 15.9

   Accessing pointer with a non-address value

EXERCISE 16.0

   Create a new project

EXERCISE 16.1

   Preprocessing

EXERCISE 16.2

   Declarations

EXERCISE 16.3

   Definitions

EXERCISE 16.4

   Translation

EXERCISE 16.5

   Map file

Preface

Welcome to “The Microprocessor: A Practical Introduction.”

This is an entry-level book on microprocessor architecture, with a focus on Arm architecture for Cortex-M processors due to their widespread use in today's microcontrollers. The objective is to build a strong understanding of the core concepts that can serve as a foundation to study more complex processors and systems.

We have used Cortex-M0 processor as an example to explain the underlying concepts. We have chosen it for its simplicity; it allows us to cover all the fundamental concepts without overwhelming readers with complex details. Cortex-M0 has a small instruction set that includes all the key aspects of a typical RISC processor: pipelined execution, arithmetic and logic instructions, load-store and stack operations, and program flow control. It uses an intuitive exception model that remains consistent across all Cortex-M processors. Once learned with Cortex-M0, these same concepts will be applicable while working on more complex processors within Cortex-M family.

We believe that the best way to learn about microprocessor internals is through assembly language programming. Therefore, each chapter is organized as a set of topics, where each topic describes one basic concept, explains the relevant details from the reference manual, and then provides a programming exercise for clarity.

Subsequently, we introduce C programming and demonstrate how various constructs in C are implemented on the processor. The book also describes how a C program is compiled and debugged on a target hardware, providing insights into the internals of a compiler tool chain.

Lastly, we have defined an abstract microcontroller to illustrate an implementation of an Arm processor. We use this microcontroller to explain register-level peripheral programming and peripheral APIs, and demonstrate how real-world applications can be implemented on a microprocessor.

The assembly programming examples are based on the free version of Keil MDK, using the built-in simulator without requiring an additional hardware. At the same time, these programs can also run on any Cortex-M-based hardware, thanks to the compatibility of Cortex-M0 with all the Cortex-M processors.

Darshak S. Vasavada and S. K. Sinha

Bangalore, India

24 December 2024

About This Book

The book begins with an introduction that provides an overview of different categories of microprocessors and introduces Cortex-M processors.

Chapter 1 provides the hardware basics: the processor, memory and bus system, input/output (IO) ports and interrupts, and reset, clock and power management.

The following two chapters present the microprocessor architecture concepts. Chapter 2 describes the instruction-set architecture for Cortex-M0 processor, and chapter 3 explains how these instructions get executed inside a typical RISC processor.

Chapter 4 provides an introduction to assembly programming. Chapters 5–9 get into the details of various types of operations carried out by the processor: arithmetic and logic operations, load-store operations, program control and stack operations.

Chapter 10 introduces the exception model and explains the vector table, exception handling and reset processing. Chapter 11 describes SysTick timer and core interrupts.

Chapter 12 introduces C programming and describes the structure of a C program. Chapters 13, 14 and 15 demonstrate how various C elements get implemented and executed on the processor. Chapter 16 explains the compilation process, from source files to the binary program loaded in the processor's memory.

Chapter 17 introduces the microcontroller using an abstract implementation, simplified to explain the basic structure. Chapter 18 explains IO programming, and chapter 19 illustrates a few examples of real-world applications using the abstract microcontroller.

Appendix A describes Keil MDK development environment, used to carry out the programming exercises in this book.

Appendix B describes a few topics which are part of Cortex-M0 processor but beyond the scope of this book, included for completeness.

Appendix C lists the startup code used in the programming exercises in this book.

Appendix D lists the header files for the abstract microcontroller used in chapters 17–19.

How to Read This Book

If you are already familiar with microprocessor basics and are particularly interested in the architecture for Cortex-M0 processor, the introduction and chapters 2 and 10 will provide a comprehensive overview. The introduction provides a high-level overview of Arm Cortex processors, while chapter 2 covers Cortex-M0 instruction-set architecture and chapter 11 explains the core exception model. Additionally, chapter 11 describes SysTick timer and core interrupt handling.

If this is your first exposure to a microprocessor system, chapter 1 will introduce you to the necessary hardware basics. Following this, chapters 2, 3 and 10 explain the core architectural concepts. Chapters 4–9 will take you deeper into Cortex-M0 instruction set through hands-on programming, and chapters 10 and 11 will introduce you to system-level programming. Collectively, chapters 1–11 provide a strong foundation for the architectural concepts. Appendix A will get you started with assembly programming, and appendix B introduces advanced topics from Cortex-M0 processor for you to continue explorations beyond this book.

Chapters 12–16 are optional. These chapters introduce C programming constructs and show how they are implemented on Cortex-M0 processor. You may glance through them first, and then revisit them as you get deeper into embedded C programming. Appendix C explains the startup code, completing the overall picture of program execution.

Chapters 17–19 provide an introduction to the microcontroller. Here, we have defined an abstract microcontroller that explains the working principles without overwhelming you with details. If you have worked on a real microcontroller, these chapters may be an easy read for you, where you might get clarity on certain aspects you might have missed out earlier. On the other hand, if this is your first exposure to a microcontroller, the concepts in these chapters will guide you to program a real microcontroller. Appendix D provides header files for the abstract microcontroller, which can be used to implement peripheral API on a real hardware.

The companion website provides a template project along with the startup code to carry out the assembly programming exercises in this book.

The chapter map is shown in figure 1.

Figure 1 Chapter map.

We believe this structure will help you to navigate through the content effectively and select your engagement with the book according to your background and interests.

Acknowledgements

We express our heartfelt thanks to all our students and the many teachers who almost forced us to write this book, without whom this book would not have happened!

Our thanks to Professors T Matthew Jacob and YN Srikanth of IISc, Bangalore, for their thoughtful insights at the formative stage of the book. A big thank-you to Arun Hiregange for the working discussions and meticulous technical review.

Our sincere thanks to the Arm team: Joseph Yiu for the comprehensive technical review, Andrew Pickard for the code template, and Christopher Seidl and Andreas Barth for valuable inputs on Keil MDK. Special thanks to Liz Warman, Arm Education, for organizing such an accomplished team of reviewers. And thank you, our friends in Arm India, Apurva Varma and Neeraj Singh, for your guidance at the pre-publication stage of the book.

Working with Sandra Grayson at John Wiley Inc. has been an absolute pleasure. Thank you for your enthusiasm, commitment and unwavering support throughout the publication process. Journey from the first draft to the publication was arduous, but you made it so comfortable! Our thanks to the production team for their diligence in shaping this book through its refinements.

Finally, we owe our deepest gratitude to our students at the Indian Institute of Science. Their passion for learning and affection for us have been the source of energy, fuelling the journey from the conception of the book to its realization.

About the Companion Website

This book is accompanied by a companion website:

www.wiley.com/go/vasavada/Microprocessor

Introduction

Let us begin by asking:

What is a microprocessor?

Intel, which is credited with the first microprocessor (4004, in 1971), answers this question thus: “The microprocessor, also known as the central processing unit (CPU), is the brain of all computers.”

This comparison of microprocessor with the human brain is quite apt. In a human mind–body system, the brain receives inputs from sensory organs (eyes, ears, skin), processes the information received and takes decisions. To the outside world, the decisions taken by our brain are reflected in what we speak, how we walk, etc.

We do not see our brain. And we do not see the microprocessor in a computer system – it is hidden inside the system and not directly accessible to the user. What we get to work with are the inputs and outputs of the system.

However, this comparison ends here! We have a very limited understanding of our brain. But we understand microprocessors very well. By the time we complete our journey, you will know much more about microprocessors than you do about your brain!

1 MICROPROCESSOR SYSTEM

Figure I.1 shows a diagram of a microprocessor system, simplified for the purpose of learning.

Figure I.1 A simplified microprocessor system

As shown in the figure, a microprocessor system receives inputs and produces outputs. An input device can be as simple as a push button, or very complex as a video camera. Similarly, an output device can be a simple two-lead LED, or a far more complex LCD screen. Processor may also interact with electro-mechanical devices, for example, motors in a robotic system. Such systems may involve inputs from a variety of sensors: distance, speed, acceleration, etc. Many systems use communication devices such as Universal Serial Bus (USB) or Ethernet for exchanging information with the external world. To interact with an input/output (IO) device, a microprocessor uses an IO port, which acts as a bridge between the processor and an IO device.

A microprocessor system processes the inputs and generates the outputs according to a program stored in the memory. A program could be an algorithm, a set of equations, or logical statements, typically written in a high-level language such as C or C++. Since the microprocessor can ‘understand’ only binary language, we convert a C/C++ program into binary machine codes using a software tool called a compiler. Just as our brain uses memory cells to remember various algorithms (for example, how to speak) and related data (various words that we speak), the microprocessor system uses memory devices to store the program instructions and the associated data.

Apart from being used in desktop and mobile computers, microprocessors are used in a large number of systems where they are embedded deep within the system. Examples of embedded applications are numerous, such as playing music or displaying pictures, controlling air-fuel mixture in a car's engine, managing the autopilot mode of an aeroplane, processing a variety of biomedical signals such as in an ECG or a blood-pressure monitor, processing camera information to drive motors in a robot, processing pressure and temperature in an industrial control system, processing enormous amounts of data on the servers – the list is endless.

Depending on the applications in which they are used, microprocessors vary in their capabilities. For example, a microprocessor that controls mixing air and fuel in a car engine has to be a lot more powerful than a microprocessor in a digital thermometer, but at the same time, it does not require capability to process audio, video and image data like the ones in our mobile phones do.

To understand this spectrum of microprocessors, ranging from a tiny microcontroller inside a remote control to the one powering a cloud server, let us divide them into three broad categories:

Microcontroller processors

Real-time processors

Application processors

Let us discuss each briefly.

2 MICROCONTROLLER PROCESSORS

Microcontrollers deploy the simplest form of microprocessors. They are used in many everyday devices such as remote controllers, digital thermometers, wearable devices and home appliances.

2.1 Hardware

Microcontrollers are designed for compact and power-efficient applications. They integrate a processor, memory and IO interfaces on a single chip. Microcontrollers are implemented as Systems-on-Chip (SoCs), reducing the overall system complexity and cost, and, at the same time, improving hardware reliability. Their small size and low power consumption make them ideal for applications where space and energy are at a premium.

2.2 Software

Microcontrollers are typically used in dedicated systems that perform specific tasks. Simple systems carry out repetitive activities running in a loop. Often known as ‘bare-metal’ systems, these are standalone systems without an operating system (OS). More complex systems deploy a real-time operating system (RTOS) to implement multitasking applications.

Power-sensitive systems go into a sleep state after completing their task, exploiting power-saving modes available in microcontrollers, and wake up again when new inputs are available.

2.3 Applications

Microcontroller processors are characterized by low software complexity, high power efficiency and small silicon area on the chip. They are tiny little brains that run numerous devices in automotive, industrial, medical, building automation and many more segments. Let us take a few examples:

Tens of microcontrollers are used inside a car, to carry out various tasks, such as checking seat-belt status, measuring tire pressure, controlling door lock, winding up window glass etc.

Microcontrollers are used extensively in home appliances. For example, microwave ovens use microcontrollers for on/off and timing control. Washing machines use them to control the speed and timings of their motors and operate water inlet and outlet valves.

Microcontrollers also proliferate medical equipment such as digital thermometers, blood-pressure meters, pulse-oximeters and so on, measuring various body parameters and displaying them on a small display.

Finally, microcontrollers play a major role in enabling the last leg of Internet of Things (IoT) systems. They provide the interface between the digital world and the physical sensors and actuators, enabling real-time data collection, processing and control in a variety of interconnected devices.

3 REAL-TIME PROCESSORS

Moving up the complexity scale, next in the series are the real-time processors. They are used in time-critical systems, where a significant amount of data needs to be processed within a specific deadline, such as an aircraft landing system or performing a robotic surgery. Often characterised as the systems where ‘a late answer is a wrong answer’, real-time processors are critically important in automotive, industrial, networking and many other systems.

3.1 Hardware

Real-time data-processing systems require significantly more computation power to process large volumes of data within a specific time frame. Hence, these processors run at a higher clock frequency compared to the microcontroller processors.

Real-time processors are accompanied by on-chip memories to store time-critical data and code. However, the on-chip memories are limited in size, and hence, such systems typically need a storage device (such as an SD card or a solid-state drive) to store the program, and a large external memory (RAM) to run the program. Since external memories are slow in speed, many systems also deploy on-chip cache memory that stores frequently accessed code and data to improve system performance.

3.2 Software

A real-time application is implemented as multiple threads running concurrently. Such systems use an RTOS that schedules threads according to their priorities to meet the deadlines. An RTOS is a very lightweight OS that provides multi-tasking capability to a system. Since it has little overheads, an RTOS is significantly more responsive to external inputs compared to a desktop OS, and hence, well-suited to meet real-time requirements.

Such systems often use a boot-loader code that loads the program from the storage device to the memory. Bootloaders often have the capability to upgrade the program for bug fixes and feature enhancements.

3.3 Applications

Real-time processors are used where time is of essence. These processors are designed to perform tasks within very strict time constraints, often requiring precision down to nanoseconds. Here are some examples of systems implemented using a real-time processor.

A power-train control module, also known as an engine control unit (ECU), processes signals from numerous sensors, including those measuring air and fuel intake, oxygen levels in the exhaust, and various shaft positions in the engine. It uses this data to control air and fuel injection and ignition timings, ensuring precise operations that result in high fuel efficiency, even at high vehicle speeds.

A wireless modem in a mobile phone converts digital data into radio signals for transmission and vice versa at very high data rates. It runs sophisticated algorithms to improve reliability in the presence of interference and noise. Since the same medium is used by multiple devices for communication, these activities must be carried out with a very high degree of precision.

A solid-state drive (SSD) controller provides an interface between the processor and the storage device. It implements error correction, wear-levelling and garbage collection algorithms to improve the lifespan and efficiency of the storage device. These operations are carried out at a very high speed, allowing us to enjoy watching a video stored in an SSD without a glitch!

Microcontrollers vs Real-Time Processors

Please note that while real-time processors are specifically designed to build high-speed, time-critical systems, many real-time systems are also implemented using microcontrollers. Audio equipment, ECG monitor, precision cutting machines are some of the examples that can be implemented using microcontrollers.

The key difference between microcontrollers and real-time processors lies in their data processing capabilities. Real-time processors are required when we need to process large amount of data within a very short time frame. In such scenarios, the processing power and the small size of the on-chip memory become limiting factors for microcontrollers.

With the advancement of technology, microcontrollers run at higher clock speeds and pack more on-chip memory. Hence, they are being increasingly used for applications in the real-time world, blurring the line between microcontrollers and real-time processors.

4 APPLICATION PROCESSORS

At the high end of the spectrum are application processors, the powerhouses behind computing devices like smartphones, tablets and cloud servers. Unlike the microcontrollers or real-time processors that run dedicated applications, application processors execute multiple applications using a general-purpose OS, which requires processing power, combined with the ability to manage large amounts of memory.

4.1 Hardware

Application processors use one or more powerful processor cores operating at a few GHz clock speed. These processors are accompanied by special-purpose coprocessors for high-speed computations required in graphics, multimedia processing and machine-learning algorithms.

Application processors typically use several GBs of RAM, shared between multiple applications. They contain a memory management unit (MMU) that allows an OS to implement virtual memory to share the memory between multiple applications. An MMU is also a key component in providing security, and protects the OS and applications from unauthorized access either by a malfunctioning application or attacks from harmful programs.

Lastly, application processors are accompanied by high-speed peripheral ports for networking, storage and high data-rate IO devices such as a camera or a display.

4.2 Software Configuration

Application processors are designed to run operating systems that can run multiple application programs. Some of these processors also support hardware virtualization, allowing them to run multiple operating systems simultaneously on the same hardware.

An OS is a complex piece of software, typically spanning millions of lines of code that manages various resources in the system. At the heart of the OS is a scheduler that schedules different applications in a way that they appear to be running simultaneously to us. OS also includes a memory management subsystem to share memory between multiple applications, and file subsystems to efficiently store applications and related data on storage devices. Not directly visible to us are various low-level device drivers that communicate with networking and IO devices.

The system contains a large number of programs stored in the file system. Some of these are system programs that run continuously, while others run as required by the user. Many of such systems have the facility to download new applications and update them over the network on an ongoing basis.

4.3 Applications

Application processors are at the forefront, powering the cutting-edge devices such as mobile phones, personal computers and servers. With Linux kernel running on these processors, they are used in a vast number of embedded applications as well.

In consumer electronics, these processors enable multimedia functionalities in set-top boxes and in-car infotainment systems, supporting high-definition media playback, efficient content management and advanced user interfaces.

For networking devices like routers and firewalls, application processors perform complex routing and implement advanced security protocols.

In healthcare, application processors are used in patient monitoring systems and medical imaging devices to process biomedical signals and high-resolution images.

Application processors form the backbone of IoT systems; they process large volumes of data, run sophisticated algorithms and take complex decisions.

Many applications, such as kiosks or automatic teller machines (ATMs), run on application processors as they provide a desktop or a tablet-like environment for user interactions, even though the application themselves may not require high data-processing capabilities.

These are a few examples to give you an idea. The actual usage of application processors in embedded applications is vast and diverse, likely to explode with the use of AI and machine learning in years to come.

Are application processors suited for real-time applications?

Traditionally, real-time applications have been designed with a stringent focus on guaranteeing response times and never missing deadlines. Use of a general-purpose OS for real-time systems was unacceptable – they were considered too ‘bulky’ as they could not respond to deadlines fast enough.

However, application processors are becoming more powerful, and hence, they are able to respond to the deadlines much better, even while running a general-purpose OS. At the same time, modern real-time systems require sophisticated user interfaces (including cameras, displays and speech recognition) and network connectivity for data analysis and running AI/ML algorithms. Hence, many software architects find it convenient to use an OS that provides all these features, and additionally, allows easy application updates, resulting in constantly evolving software.

It is important to note, however, that general-purpose OS is not designed to meet real-time requirements, and can miss deadlines once in a while. To address these, some systems simply use more processor cores, faster clock and more memory to reduce the chances of missing deadlines. They also implement acceptable workarounds in case the system occasionally misses a deadline.

Time-critical systems often deploy a combination of one or more application processors and a microcontroller on the same chip. The application processor runs the OS and applications, while the microcontroller is used to run time-critical tasks. This dual approach combines features of a modern system, while meeting the hard deadlines of a real-time system.

5 OVERVIEW OF ARM CORTEX PROCESSORS

Arm architecture has been constantly evolving over time.

Armv1 and Armv2 were early versions designed for personal computers, with processors running at lower tens of MHz. They established the foundational reduced instruction set computer (RISC) principles, achieving similar performance to more complex architectures but with significantly fewer transistors. This efficiency was the key to their low power consumption and cost-effectiveness.

Armv3 onwards, cores were licensed to third-party vendors. Armv4 and Armv5 were extensively used in mobile phones for their power efficiency and compact design, evolving from feature phones to smartphones due to their multimedia capabilities. Beyond phones, these processors also powered embedded systems, automotive applications, and consumer electronics such as set-top boxes and digital cameras.

Armv6 introduced Cortex-A processors aimed at high-performance computing, and Cortex-M processors for low-power and cost-sensitive applications.

Armv7 further expanded Cortex-M family to include signal processing and floating-point computation capabilities. It also introduced Cortex-R processors, optimized for time-critical applications.

Armv8 introduced 64-bit processing with the AArch64 instruction set, alongside enhanced security features. It also included vector processing capabilities for signal processing and machine-learning tasks.

Armv9 is the latest architecture at the time of writing, building on Armv8 with further enhancements in security and performance optimizations for AI and machine learning computations.

Arm defines three architecture profiles for their Arm® Cortex® processors:

Arm Cortex-A, application processors

Arm Cortex-R, real-time processors

Arm Cortex-M, microcontroller processors

Let us discuss each briefly.

5.1 Cortex-A

Cortex-A processors are a series of high-performance processors designed to run multiple applications using a general-purpose OS.

High-end Cortex-A processors drive consumer products such as mobile phones, tablets and laptops. In embedded systems, they are ideal for demanding applications such as robotics and computer vision.

Mid-range Cortex-A processors provide reasonable computation power to entry-level phones as well as embedded systems that require moderate computation power, such as infotainment systems and smart-home devices.

Entry-level Cortex-A processors are power-efficient and often used in embedded systems primarily due to their ability to run an OS, for example, in point-of-sales terminals and industrial control panels.

5.2 Cortex-R

Cortex-R series includes a range of high-performance processors optimized for hard real-time applications. Unlike Cortex-A processors, which are designed for general-purpose computing with the capability to run an OS, Cortex-R processors are tailored for specific, computation-intensive applications that do not require a full OS. Since they are fine-tuned for single-application use cases, Cortex-R processors are better suited for applications that require high responsiveness and low latency.

Cortex-R processors also contain features for safety-critical systems. For example, a dual-core Cortex-R processor can be used in a ‘lock-step’ mode, where both cores execute exactly the same instructions to provide redundancy, in case one of them fails. They support memory interface with error correction code (ECC) to detect and correct memory corruption, especially in an environment with high electromagnetic interference that can cause bits to flip inside memory cells.

Cortex-R processors are also certified for certain medical, industrial and automotive standards and provide a long life-cycle support necessary for products in these segments.

5.3 Cortex-M

Cortex-M processors are integrated into microcontrollers along with memory and IO ports, suited for applications where low power, compact size and cost are the key factors.

Shown below is a list of Cortex-M processors at the time of writing this book:

Cortex-M0 is the smallest Cortex-M processor, designed for entry-level microcontrollers.

Cortex-M0+ is a highly energy-efficient processor, specifically useful in wearables for healthcare and fitness.

Cortex-M3 has more powerful instruction set, and hence, provides more computation power, specifically useful in smart-home devices.

Cortex-M4 further includes digital signal processing (DSP) instructions and optional integration of a single-precision floating point unit (FPU). These features make Cortex-M4 useful for mixed signal (analog and digital) and control systems.

Cortex-M7 is a high-performance Cortex-M processor, which also supports cache and external memory. Cortex-M7 has the capabilities of a real-time processor, particularly useful for computationally intensive automation applications.

Cortex-M23, Cortex-M33 and Cortex-M35P processors include TrustZone security, which protects critical information within a system. Cortex-M35P has additional security features to protect confidential data from several forms of physical security attacks. This helps keeping personal information safe in gadgets like smartwatches and home security systems.

Cortex-M52, Cortex-M55 and Cortex-M85 processors each implement Helium

TM

technology that supports vector instructions, making them useful in signal processing and machine-learning applications such as audio processing, power electronics, voice command recognition and still or low frame-rate image processing.

Arm cores are processor designs that various semiconductor companies can license and integrate into their silicon chips. Arm processors, therefore, are always a part of a semiconductor company's product. If we want to use an Arm processor, we would have to pick up a processor that uses an Arm core inside – we cannot buy only an Arm processor!

When integrated inside a product, we often use the term ‘core’ for the microprocessor, and the integrated silicon chip is often referred to as the ‘processor’. The term ‘processor’ could, therefore, either mean the core or the integrated chip – the meaning becomes clear from the context. For example, when we talk about processor architecture, or the processor running a program from memory, the term ‘processor’ usually refers to the core. But if we say that a mobile phone uses a multi-core processor, it refers to an integrated chip.

CHAPTER 1Microprocessor System

About this chapter

In this chapter, we will familiarize ourselves with the basics of hardware organization for a microprocessor system. Doing so will help us gain a deeper and clearer understanding of how programs execute within such systems.

What do we learn?

What are the various components of a microprocessor system?

What are the various parameters that determine the capability of a processor?

How is data stored and accessed from the memory?

What are the various types of memory devices?

What are the different buses inside a microprocessor? What information do they carry?

How do input/output (IO) devices interface with the processor?

What is an interrupt?

What are clock, reset and power management blocks in a microprocessor system?

By the end of this chapter, we will have an overview of Cortex-M0 processor.

1.1 INTRODUCTION

Figure 1.1 shows the key components of a simple microprocessor system.

The central processing unit (CPU), also called the microprocessor (or sometimes just the processor), receives information from input devices, processes it according to the program instructions stored in the memory and sends the processed information to output devices. Even though we called it the brain of the system, the CPU does not have any intelligence by itself; it simply executes the instructions stored in the program. Hence, it is the program that determines the functionality of a microprocessor system.

The system needs memory to store the program, which consists of instruction codes and accompanying data. Instruction codes determine the operations carried out by the program, and the data provides the necessary information used by these instruction codes to carry out the required operations.

IO devices are connected to the processor via IO ports, also known as peripheral ports. The processor interacts with these ports for receiving inputs and sending outputs. An IO port can also seek the processor's attention by generating an interrupt.

Memory devices and IO ports are connected to the processor using a bus, which carries the electrical signals from the processor to these devices and vice versa.

The reset unit initializes the processor when powered on. All the blocks in the system operate synchronously with the help of the clock signals provided by the clock unit. The power management unit supplies required voltages to all the units in the system as well as supports power-saving modes to optimize power consumption in the system.

Figure 1.1 A simple microprocessor system.

Microcontroller

In earlier implementations, the silicon chip contained just the microprocessor and nothing else. Everything else – memory devices, IO ports, clock and power management had to be procured as individual chips and soldered on a printed circuit board (PCB). Not only that made the system designer's job cumbersome, the boards were bulky, slow and vulnerable to environmental conditions.

Over the years, the technology behind chip manufacturing has improved considerably and today's manufacturing processes permit integration of many devices on a single chip. Along with the microprocessor, it is now possible to have memory devices, IO ports and other dedicated hardware targeted for specific applications on the same chip. A microprocessor, with an appropriate program loaded inside its memory, and interfaces to IO ports contains the required intelligence and connectivity to control a system. Hence, such an integrated device is known as a microcontroller.

We will get into the internals of a microcontroller in chapters 17 and 18.

1.2 PROCESSOR

A microprocessor is an integrated circuit consisting of thousands, millions or even billions of transistors, working together to carry out the functionality as specified by the program.

Microprocessors are designed to meet a wide range of requirements and price points, catering to diverse applications ranging from low-cost embedded controllers to high-performance computers. The capabilities of a microprocessor depend on various aspects, such as the number of data bits it can process in a single instruction, the speed at which it can operate and the complexity of the instructions it can execute. Many microprocessors also enhance their capabilities by having multiple cores and additional hardware blocks that increase their computation power.

Let us look at the key factors that determine the capabilities of a microprocessor.

1.2.1 Word size

The number of data bits that a microprocessor can process in a single instruction is referred to as its word size. Typically, the word is size a power of 2, ranging from 8 bits in tiny microcontrollers to 64 bits in powerful microprocessors. A larger word size enables the processor to handle larger units of data at once, enhancing its capability to perform complex computations and efficiently access larger memory addresses.

A more precise definition of the width of an architecture is the width of the general-purpose registers in the register bank. These registers are used to hold data being computed inside the processor.

For example, with HeliumTM in Armv8.1-M architecture, the processor has 128-bit vector processing capability. However, it is still considered a 32-bit architecture because its general-purpose registers are 32-bit wide.

We will discuss general-purpose registers at length in the next chapter.

1.2.2 Clock speed

The clock speed reflects the number of computations a microprocessor can perform in one second. It can range from a few hundred kHz to a few GHz: processors running at slow speeds are useful for low-power applications, whereas the ones running at higher speeds provide more computation power.