
The Microprocessor
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
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.
More details
Other editions
Additional editions

Persons
Darshak S. Vasavada has extensive corporate as well as teaching experience in embedded DSP and multimedia systems. At present, he teaches real-time embedded system design at Robert Bosch Center for Cyber-Physical Systems at Indian Institute of Science, Bangalore.
S. K. Sinha, retired from Department of Electronic Systems Engineering (DESE, earlier known as CEDT), Indian Institute of Science, Bangalore, set up the first embedded systems lab at CEDT and has helped introduce MTech courses in several colleges in India. At present, he is Chief Architect at Lab To Market Innovations, specializing in reliable IIoT systems.
The authors have contributed to several workshops on embedded systems for teachers and students in various colleges, which have been the source of motivation behind this book.
Content
List of Exercises x
Preface xiii
About This Book xv
How to Read This Book xvi
Acknowledgements xviii
About the Companion Website xix
Introduction xxi
Chapter 1 Microprocessor System 1
1.1 Introduction 2
1.2 Processor 3
1.3 Memory 5
1.4 Memory Devices 7
1.5 Bus 10
1.6 IO Ports 14
1.7 Reset, Clock and Power Management 16
1.8 Overview of Arm Cortex-M0 Processor 17
1.9 Summary 20
Chapter 2 Instruction Set Architecture 25
2.1 Introduction 25
2.2 Registers 27
2.3 Instruction Set 28
2.4 Structure of an Instruction 30
2.5 Data-Processing Instructions 33
2.6 Memory-Access Instructions 37
2.7 Program-Control Instructions 43
2.8 Summary 47
Chapter 3 Program Execution 49
3.1 Introduction 49
3.2 Program 50
3.3 Inside the CPU 52
3.4 Fetch Unit 55
3.5 Decode Unit 57
3.6 Execution Unit 59
3.7 Instruction Execution 63
3.8 Processor Pipeline 66
3.9 Summary 68
Chapter 4 Assembly Programming 71
4.1 Statements 72
4.2 Labels 73
4.3 Sections 75
4.4 Text Section 77
4.5 Data Sections 84
4.6 Summary 90
Chapter 5 Arithmetic Operations 93
5.1 Arithmetic Instructions 94
5.2 Unsigned Integers 96
5.3 Signed Integers 99
5.4 APSR Flags 101
5.5 Condition Codes 106
5.6 Summary 110
Chapter 6 Bit-Level Operations 113
6.1 Boolean Instructions 114
6.2 Bit Manipulation 116
6.3 Shift Operations 119
6.4 Word-Length Extension 125
6.5 Byte Ordering Instructions 127
6.6 Summary 129
Chapter 7 Load and Store Operations 131
7.1 Introduction 131
7.2 Alignment 133
7.3 Endianness 135
7.4 Basic Load and Store Operations 140
7.5 Data Types 142
7.6 Offset Addressing 145
7.7 Summary 153
Chapter 8 Branch and Subroutine 155
8.1 Program-Control Instructions 155
8.2 Branch 156
8.3 Conditional Branch 158
8.4 Indirect Branch 162
8.5 Subroutines 166
8.6 Nested Subroutines 169
8.7 Summary 173
Chapter 9 Stack Operations 175
9.1 Introduction 175
9.2 What Is a Stack? 177
9.3 Stack in Cortex-M 0 178
9.4 Stack Operations 180
9.5 Creating a Stack 182
9.6 Using the Stack 185
9.7 Local Variables 190
9.8 Summary 193
Chapter 10 Exceptions 195
10.1 Introduction 196
10.2 Exception Model 198
10.3 Vector Table 200
10.4 Reset 206
10.5 Faults 209
10.6 Exception Stack Frame 211
10.7 Summary 215
Chapter 11 SysTick and Core Interrupts 217
11.1 Introduction 218
11.2 SysTick 218
11.3 SysTick Programming Model 219
11.4 Programming SysTick 222
11.5 Using SysTick 224
11.6 Polling with SysTick 226
11.7 SysTick Interrupts 228
11.8 Interrupt Masking 232
11.9 Non-maskable Interrupt (NMI) 235
11.10 Summary 237
Chapter 12 Introduction to C Programming 239
12.1 Programming Languages 240
12.2 Structure of a C Program 241
12.3 Functions 244
12.4 Data 247
12.5 Header Files 250
12.6 Overview of C Language 257
12.7 Summary 259
Chapter 13 Basic Data Types 263
13.1 Characters and Strings 263
13.2 Integers 268
13.3 Floating-Point Numbers 277
13.4 Floating-Point Operations 280
13.5 Type-Casting 284
13.6 Summary 285
Chapter 14 Functions 289
14.1 Function Calls 290
14.2 Arguments 292
14.3 Local Variables 295
14.4 Conditional Execution 297
14.5 Selection 301
14.6 Loops 305
14.7 Summary 312
Chapter 15 Extended Data Types 315
15.1 Arrays 315
15.2 Structures 319
15.3 Pointers 323
15.4 Arrays and Pointers 327
15.5 Pointer to a Structure 330
15.6 Pointer Arithmetic 332
15.7 Uninitialized Pointers 334
15.8 Summary 339
Chapter 16 Compilation Process 341
16.1 Overview of the Compilation Process 342
16.2 Preprocessing 345
16.3 Compilation 348
16.4 Assembler 354
16.5 Linker 357
16.6 Executable Program 361
16.7 Summary 364
Chapter 17 Microcontroller 367
17.1 Introduction 368
17.2 Block Diagram 369
17.3 Pin Diagram 372
17.4 Reset, Clock and Power Management 373
17.5 Peripheral Interrupts 379
17.6 Peripheral Registers 382
17.7 Peripheral API 387
17.8 Summary 389
Chapter 18 IO Programming 393
18.1 IO Devices 394
18.2 GPIO 396
18.3 Timer 400
18.4 ADC 403
18.5 DAC 407
18.6 UART 410
18.7 Interrupts 414
18.8 Summary 419
Chapter 19 Microprocessor Applications 423
19.1 LED Brightness Controller 424
19.2 Ambient Light Sensor 427
19.3 Energy-Efficient Coding 430
19.4 Temperature Monitoring 433
19.5 Motor Speed Control 435
19.6 Summary 441
Appendix A Programming Environment 443
A.1 Introduction 444
A.2 Keil MDK 446
A.3 Assembly Programming Setup 449
A.4 Writing and Building Assembly Programs 452
A.5 Debugging an Assembly Program 454
A.6 c Programming Setup 458
A.7 Writing and Building C Program 460
A.8 Debugging A C Program 461
A.9 Debugger 464
Appendix B Advanced Topics 467
B.1 System-Control Instructions 467
B.2 OS Support 470
Appendix C Startup Code 475
C.1 OS-Less System 475
C.2 Startup Code 478
C.3 Linker Script File 481
Appendix D AM0 Header Files 483
D.1 Register Header File 483
D.2 AM0 Header File 484
Glossary of Acronyms 487
References 491
Index 493
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...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.