Embedded System Design Third Edition Santanu Chattopadhyay Newest Edition 2025
Embedded System Design Third Edition Santanu Chattopadhyay Newest Edition 2025
https://ebookgate.com/product/embedded-system-design-third-edition-santanu-chattopadhyay/
DOWNLOAD EBOOK
Embedded System Design Third Edition Santanu Chattopadhyay
pdf download
Available Formats
https://ebookgate.com/product/embedded-linux-system-design-and-
development-1st-edition-p-raghavan/
ebookgate.com
https://ebookgate.com/product/embedded-systems-design-2nd-edition-
steve-heath/
ebookgate.com
https://ebookgate.com/product/hybrid-cmos-single-electron-transistor-
device-and-circuit-design-first-edition-santanu-mahapatra/
ebookgate.com
https://ebookgate.com/product/embedded-systems-architecture-
programming-and-design-2nd-edition-raj-kamal/
ebookgate.com
https://ebookgate.com/product/fast-and-effective-embedded-systems-
design-1st-edition-rob-toulson/
ebookgate.com
https://ebookgate.com/product/professional-optical-system-design-
fischer/
ebookgate.com
https://ebookgate.com/product/making-embedded-systems-design-patterns-
for-great-software-2nd-edition-elecia-white/
ebookgate.com
https://ebookgate.com/product/power-system-relaying-third-edition-
stanley-h-horowitz/
ebookgate.com
Third Edition
EMBEDDED
SYSTEM DESIGN
SANTANU CHATTOPADHYAY
EmbEddEd SyStEm dESign
THIRD EDITION
SANTANU CHATTOPADHYAY
Professor
Department of Electronics and Electrical Communication Engineering
Indian Institute of Technology Kharagpur
Delhi-110092
2023
To
SANTANA, MY WIFE
My inspiration
and
SAYANTAN, OUR SON
Our hope
Contents
Preface..........................................................................................................................................................................................xi
Preface to the First Edition............................................................................................................................................. xiii
Acknowledgements............................................................................................................................................................. xvii
1. Introduction...................................................................................................................................... 1–7
1.1 Features of Embedded Systems 2
1.2 Design Metrics 3
1.3 Embedded System Design Flow 4
1.4 Conclusion 6
Exercises 7
5. Interfacing..................................................................................................................................... 57–81
5.1 Serial Peripheral Interface (SPI) 57
5.2 Inter-Integrated Circuit (IIC, I2C) 60
5.3 RS-232C 62
5.4 RS-422 63
5.5 RS-485 63
5.6 Universal Serial Bus (USB) 64
5.6.1 Physical Interface 68
5.6.2 USB Connectors 68
5.7 Infrared Communication—IrDA 71
Contents vii
8. Specification Techniques....................................................................................................132–163
8.1 Introduction 132
8.2 StateChart 133
8.2.1 Modelling Hierarchy 134
8.3 Specification and Description Language (SDL) 139
8.3.1 Signal Communication 142
8.3.2 Timer 144
8.4 Petri Nets 144
8.4.1 Basic Petri Nets 145
8.4.2 Properties of a Petri Net 149
8.4.3 Extensions to Petri Nets 150
8.4.4 Embedded System Modelling with Petri Nets 151
8.5 Unified Modelling Language (UML) 154
8.5.1 Activity Diagram 155
8.5.2 Class Diagram 155
8.5.3 Communication/Collaboration Diagram 157
8.5.4 Component Diagram 157
8.5.5 Use Case Diagram 158
8.5.6 Sequence Diagram 158
8.5.7 Other Diagrams 159
8.5.8 UML Specification of an Elevator Control System 160
8.6 Conclusion 162
Exercises 162
9. Hardware–Software Cosimulation..................................................................................164–172
9.1 Dimensions in Cosimulation 165
9.2 Cosimulation Approaches 166
9.3 A Typical Cosimulation Environment 167
9.3.1 Abstract-level Cosimulation 168
9.3.2 Detailed-level Cosimulation 169
9.3.3 Interface Issues 169
9.3.4 Automatic Interface Generation 170
9.4 Conclusion 171
Exercises 171
Bibliography.......................................................................................................................................... 245–249
Index......................................................................................................................................................... 251–257
Preface
The third edition of the book incorporates two new chapters—Sensors and Actuators and
Security in Embedded Systems. As embedded systems are interacting more and more with the
environment, different types of sensors are being used by them to get the input parameters. An
embedded system professional must possess good knowledge about the types of these sensors,
their working principles, cost, etc., and should be able to choose the right one from various
alternatives available—for an application design. A full chapter has been devoted for the same
in this new edition. It starts with the parameters of sensors and their classification, followed
by discussion on linear and rotational position sensors, strain sensors, temperature sensors,
acceleration sensors, proximity sensors, Hall-effect sensors, etc. Several types of actuators have
also been enumerated. Chapter 12 of this book discusses the security concerns for embedded
system design. As embedded systems are battery operated and the battery technology is not
advancing at the same rate as computing technology, a battery gap is being felt increasingly
by the system designers. As embedded systems are mostly resource constrained, it is often
difficult to implement rigorous security protocols in them, unlike other computing systems.
On the other hand, increasing use of embedded systems in safety-critical operations, often
dealing with confidential information, has made security a very important aspect. The chapter
discusses the vulnerabilities faced by such a system. Different levels of the system design and
usage may have varying security concerns. Design challenges of a secure embedded system
have been enumerated. Different types of security attacks that may happen on an embedded
system and their probable prevention strategies have also been detailed. A case study on Smart
Card security concerns has been included for better understanding of the topic.
With the inclusion of these two chapters, the book now comprises thirteen chapters, which
make the book complete and more informative. I believe the new edition will be great value to
the students and working professionals in the domain of Embedded Systems. Like the previous
editions, the present edition is also expected to receive wide acceptance in the academic and
professional world.
Santanu Chattopadhyay
Preface to the First Edition
(SPI), Inter-Integrated Circuits (IIC), RS-232C, etc. The advanced versions, such as RS-
422 and RS-485 are also presented. It is followed by a detailed discussion on USB. The
physical, electrical and communication standards of USB are presented. Next, the wireless
communication techniques, such as IrDA and Bluetooth have been dealt with. Many of the
embedded applications, particularly in the automotives, utilize the Controller Area Networking
(CAN) for information exchange between subsystems. It has also been discussed.
Chapter 5 is on specification techniques for embedded systems. This enables the readers
to get familiar with the modelling techniques for the real-world systems. It begins with the
discussion on StateChart, a modified version of finite state machines. Several examples have been
included to illustrate the specification methodology. It is followed by another strategy, called
SDL, particularly suitable for describing distributed systems. A very powerful mathematical
technique for describing the behaviour of asynchronous systems is the PetriNets. The basic
PetriNet structure has also been extended in several ways to handle real-time systems. All
these have been discussed with a good number of illustrations. A graphical object-oriented
method for embedded system specification is the UML. It consists of a set of diagrams that
can be utilized to describe a system hierarchically. Suitable illustrations have been included to
illustrate the specification process.
Chapter 6 deals with real-time operating systems. This forms the kernel of any moderate‑to-
large sized real-time embedded system. First, the tasks have been classified into several
categories, such as soft, firm, and hard real-time tasks. Different scheduling algorithms have
been presented, beginning with the very simple table-driven ones to the complex ones, such as
rate-monotonic scheduling, earliest-deadline first scheduling, etc. The schedulability conditions
for a set of tasks have been described. The pros and cons of the major scheduling strategies
have been discussed. The problems related to priority-based scheduling algorithms have been
presented. These include priority inversion and associated deadlock problems. The solutions
to these have also been dealt with. The other general features of real-time operating systems
have been enumerated. A number of such real-time operating systems have been studied and
their features have been compared.
Chapter 7 presents the details of hardware–software co-simulation. It addresses the
problem of verifying the correctness of the system at every stage of development. The concept
of co-simulation is presented—its categories are discussed. The techniques for homogeneous
and heterogeneous co-simulation have been presented. It also discusses the important issue of
automated interface generation that enables the completion of hardware–software co-synthesis.
Chapter 8 deals with the issues related to hardware–software partitioning of the tasks
belonging to one or more applications for a system realization. The partitioning problem
takes as input a specification, most conveniently represented as a task graph with nodes
representing individual tasks and the edges representing the amount of interactions and
dependencies between the tasks. There exist a good number of algorithms to solve this
partitioning problem targeted to architecture. These include techniques based on Integer
Linear Programming (ILP), heuristic approaches (such as Kernighan-Lin algorithm), meta-
search techniques (such as, Genetic Algorithm, Particle Swarm Optimization etc.). Each of
these categories has been discussed. The problem has been extended further to combine with
scheduling and implementation bin selection (to select among the hardware alternatives for
nodes mapped onto to hardware, and similarly for software). Another important aspect of
today’s system design is honouring the power constraints. Some power constrained mapping
solutions have also been presented.
Preface to the First Edition xv
Chapter 9 discusses the functional partitioning and optimization of task graph for an
application. The problem of functional partitioning is to reconsider a given specification and
come up with better grouping or refining the procedures within it so that the improved task
graph can be fed as input to the partitioning process to result in better solutions. It includes
steps like granularity selection, pre-clustering and N-way assignment. On the optimization
side, the chapter enumerates different loop-optimization techniques, floating-to-fixed-point
conversion algorithms, etc. The overall idea is to refine the manual specification into a form
that can lead to a better final implementation.
Chapter 10 presents discussions on low-power techniques commonly followed in embedded
system design. After presenting the basic power dissipation techniques in an electronic
system, it discusses the power reduction approaches. The power can be saved at various
levels—algorithm, architecture, logic, device, etc. For an embedded system designer, it is most
appropriate to address the power issues at algorithm and/or architectural levels. Hence, these
have been discussed in detail. The issues related to dynamic power management have been
enumerated. The shutdown prediction mechanisms have been presented for periodic real-time
tasks. The ACPI standards for power management have also been discussed.
This book is an attempt to bridge various domains of knowledge needed by an embedded
system designer. It is estimated to be covered in a single semester undergraduate/postgraduate
course on Embedded Systems. If the book can be fruitfully utilized by the students, for whom
it has been written, I will consider my efforts to be successful. All constructive suggestions for
improving the content will be welcomed.
Santanu Chattopadhyay
Acknowledgements
I must acknowledge the contribution of my teachers who taught me the subjects such as Digital
Logic, Computer Architecture, Operating Systems, Programming Languages and Semantics,
Algorithms, Networking, Compilers, VLSI Design, and so forth. The clear discussions in those
classes helped me to consolidate my knowledge in these domains and combine them properly
in framing the contents of the book. The various design problems introduced in the book have
their roots in those class lectures. I feel deeply blessed to have such a nice group of teachers.
I am also thankful to all my students, whom I have taught this subject. They all helped me to
identify the gaps and mistakes in the manuscript.
My source of inspiration for writing this book is my wife Santana, whose relentless wish
and pressure forced me to bring the book in its present shape. Over this long period, she has
sacrificed a lot in the family front to allow me to have time to continue writing, taking all other
responsibilities onto herself. I am also thankful to my son, Sayantan, for his cute comments
that kept the charm of writing rolling.
I acknowledge the authors of the books and research papers, which have been referenced
for writing this book. A detailed list has been provided in the Bibliography.
Thanks are also due to the publishers, PHI Learning, its editorial and production teams for
providing me with the necessary support to see my thoughts in the form of a book.
Santanu Chattopadhyay
1
CHAPTER
Introduction
6. Real-time system: Most embedded systems are real-time in nature. They must respond
to a request from the environment within a finite and fixed amount of time.
Failure to do so may lead to a catastrophic situation. For example, failure to activate
fire extinguishers immediately after getting a fire alarm through sensors, may destroy
the entire plant. Such systems are called hard real-time systems. On the other
hand, if the effect is not that serious, the system is a soft real-time system. For
example, failure to process the image frame just arrived may just create some noise
in the display of the image for some time.
7. Hybrid systems: Many of the real-time systems are hybrid in nature, as they include
both analog and digital components.
8. Reactive systems: Reactive systems have continual interaction with the environment.
The behaviour of the system is very much dependent on the events occurring
in the environment. This type of systems normally have a set of states. Depending
upon the occurrence of events, state transitions in the system take place. On the other
hand, a proactive system may not be interactive in nature. Once initiated, a proactive
system may work on its own to produce output.
5. Design flexibility: It refers to the effort needed to modify a system if the specification
changes to some extent later. While a software implementation is very flexible, ASIC
is the least flexible one, with FPGAs lying at an intermediary stage. The main problem
in the design change is the repetition of the NRE cost which is the minimum for
software.
6. Design turnaround time: This is the time needed to complete the design starting from
specification upto taking it to the market. Due to the very high rate of obsolesence
of electronic goods, it is imperative that this time be small. The requirement often
forces the designers to use off-the-shelf components, rather than doing a costly
redesign of system components. Design reuse is the key term here.
7. System maintainability: This refers to the ease of maintaining and monitoring the
health of the system after it has been put into the field. A good design is well
documented such that even designers excepting those who designed the system
originally, can modify the system, if necessary.
8. Testing and verification of functionality: It refers to the ability to check the system
functionality and get confidence regarding the correct operation of it. It may be
noted that in the system life-cycle, verification is generally carried out after the
design has been completed. The goal of design verification is to see whether all the
system features have been designed properly or not. There is no physical system
available at this point of time. On the other hand, testing is needed to check for
correct functioning of each unit produced. Thus, verification comes as an NRE cost
while testing comes as a part of unit cost.
cosimulator connects these two types of simulators (hardware and software) to perform the
overall simulation of the system at its behavioural level. At RT-level, a structural-level HDL
simulator can be used to simulate the RT-specification of the hardware components, whereas,
the code corresponding to the general-purpose processor can be compiled and run. Again the
cosimulator can utilize these two types of information to have a RT-level simulation of the
system. At logic level, a gate-level simulator can be used to produce the output waveforms from
the given input waveforms. The general-purpose processor simulators execute the program
code mapped onto it. The co-simulator now checks the output of both of them to produce the
final output of the system simulation. Thus the overall design methodology can be expressed
in the form of a diagram shown in Fig. 1.1.
1.4 CONCLUSION
In this chapter, we had an overview of the embedded systems, their features, design metrics,
overall design flow and the synthesis techniques. To be a successful system designer, one must
have thorough knowledge about the following:
◆ Specification techniques to be able to specify the system behaviour in a formal fashion.
◆ Hardware platforms available to realize the functionalities mapped onto hardware. This
requires us to know about the general purpose processors, Field Programmable Gate
Arrays (FPGAs), microcontrollers, digital signal processors and so on.
◆ Interfaces that are commonly used, like RS232C, USB, I 2 C, SPI, UART, CAN, IrDA,
Bluetooth, etc.
Introduction 7
◆ Sensors and actuators that can be used to interface with the environment.
◆ For efficient software design, we need knowledge about the real-time operating systems.
◆ Methodologies for hardware and software partitioning and synthesis.
◆ Automated synthesis of the interface between the system components.
In subsequent chapters we will go through discussions on each of these topics in detail.
To start with, in next two chapters we will look into the available processor architectures
that can be used in embedded system design.
EXERCISES
1.1 What is embedded system? Give as many different definitions (with justification) that
you can think of.
1.2 Identify a few embedded systems around us and justify their classification as embedded
system.
1.3 Differentiate between single-functioned and multi-functioned embedded systems. Give
examples for each of them. How do you distinguish between a multifunction embedded
system and a general desktop?
1.4 Identify a few instruments that can be part of an embedded system interacting with
the environment.
1.5 Explain the terms dependability, safety, criticality, reliability, availability with respect
to an embedded system.
1.6 What is a tightly constrained system. What are the different types of constraints
that we can encounter in embedded system design?
1.7 Distinguish between proactive and reactive systems. Give examples.
1.8 Explain the main features of embedded systems.
1.9 What is meant by design metric? Mention the various design metrics that need to be
considered in embedded system design.
1.10 What are the components of the metric system cost? How does the contribution of
the components change as we go from general processor-based design to application
specific design?
1.11 How is the performance of a system expected to change in different implementation
strategies?
1.12 What are the compelling factors that make power an important issue?
1.13 What is design turnaround time and why should it be as small as possible?
1.14 Enumerate the various steps of embedded system design.
1.15 What are the various categories of synthesis tools needed in the embedded system
design cycle? Identify some potential tools (name of the tool, manufacturer, etc.) in
each of these categories.
1.16 What do you mean by the RTL specification of software processes?
1.17 What are simulators? Mention different categories of simulators in embedded system
design with examples of actual tools (name of the tool, manufacturer, etc.) for each
category.
2
CHAPTER
ARM: An Advanced
Microcontroller
Microcontrollers are single-chip computers. In a single chip it combines a relatively simple CPU,
with supports, such as timers, serial/parallel, digital/analog, input/output lines, etc. Program
memory is generally included on-chip. Also, a typically small read/write memory (commonly
known as scratch-pad) is included in the chip. To extend program and data memory further,
proper interfacing facilities are provided.
While microprocessors are used in personal computers and other high-performance appli-
cations, microcontrollers are targeted towards small applications. The operating frequency
may be as low as 32 kHz, though there exist many high speed microcontrollers. The major
requirement of such small systems is the reduced power consumption (as noted in Chapter 1).
The next important issue is of course cost. Apart from the integration of various system com-
ponents into a single chip with reduced power consumption and cost, some of the important
features that embedded system designers look for in microcontrollers are the following:
1. Whether the highest available speed of the microcontroller is sufficient for the
application in hand.
2. The size of the chip, for example, 40-pin DIP (dual inline package), QFP (quad flat
package). This determines the size of the system and thus the device.
3. Amount of on-chip ROM/RAM space should be sufficient to hold program code.
Depending upon the design constraints, external memory may or may not be utilized.
4. Cost of a single chip, as it is going to determine the cost of the overall system.
5. The development platform should be good enough so that the design time is reduced.
It is also advisable to have on-chip debugging facility (through JTAG port) and debug
software.
6. Availability of the microcontroller chips is also another determining factor.
Various types of microcontrollers are available in the market. Some of the important ones
are—68HC11, 8051, ARM, Atmel (AVR8, AVR32), Freescale (CF, S08), Hitachi (H8, SuperH),
MIPS, NEC, PIC, PowerPC, TI MSP430, Toshiba TLCS-870, Zilog (eZ8, eZ80). In the following
section, we look into the ARM processor architecture that has many nice features supporting
embedded computation, and is, in particular, low power.
ARM: An Advanced Microcontroller 9
was extended with on-chip cache in ARM 3 processor. The third version of ARM architecture,
developed in 1992 had features like 32-bit addressing, support for Memory Management Unit
(MMU) and 64-bit multiply-accumulate instructions. It was implemented in ARM 6 and ARM 7
cores. Prior to this, in 1990, Apple took a decision to use ARM processor in their Newton PDA.
A joint venture called ARM (Advanced RISC Machines) was launched. ARM entered into the
embedded market with the release of these processors and the Apple Newton PDA in 1992. The
4th generation ARM processor came out in 1996 with the special feature of THUMB—16-bit
compressed instruction set. Though THUMB is slightly less efficient compared to the regular
32-bit ARM instruction set, it takes 40% less space. The most prominent representative of
the 4th generation ARM is the ARM7TDMI core, which is till now the most popular ARM
product. It has been used in most Apple iPod players, including the video iPod. Another
popular implementation of ARMv4 core is the Intel StrongARM processor. The 5th generation
of ARM architecture introduced in 1999 has digital signal processing capability and Java
byte code extensions to the ARM instruction set. Intel XScale processor is the most popular
implementation of the 5th generation ARM core. It is used in a number of embedded devices,
network processors, smart phones and PDAs. ARMv6 architecture anounced in 2001 features
improvements in many areas covering the memory system, improved exception handling
and better support for multiprocessing environments. It also includes media instructions to
support Single Instruction Multiple Data (SIMD) software execution. THUMB-2, an improved
THUMB instruction set defining a new set of 32-bit instructions that execute along-side
16-bit instructions in THUMB state, was introduced. It provides better support for two separate
address spaces, such that code executing in the non-secure world cannot gain access to any
address space marked as secured. The protection provided by the technology is necessary for
consumer privacy and extending a range of services such as, mobile banking and multimedia
entertainment, to widespread consumer adoption and use. The next generation ARMv7 cores
have been introduced in 2005. They come with three different processor profiles. The ‘A’
profile is for sophisticated virtual memory based OS and user applications. The ‘R’ profile
is for real-time systems, and the ‘M’ profile is optimized for microcontrollers and low-cost
applications. The ARMv7A architecture has the option of NEON technology designed to address
the next generation high performance, media intense, low-power mobile hand-held devices. It
is a 64/128-bit hybrid SIMD architecture developed by ARM to accelerate the performance of
multimedia and signal processing applications. The Vector Floating Point (VFP) coprocessor
support is also an architectural option. It supports single and double precision floating point
arithmetic, and is fully IEEE 754 compliant with suitable software library. Table 2.1 summarizes
the discussion.
1. Instruction Pipeline and Read Data Register: It gets the content of memory location
pointed to by the address bus lines A[31 : 0], of Address Register. The external 32-bit
data-in lines DATA[31 : 0] put the content into this register.
2. Instruction Decoder and Control Logic: It has a number of control inputs determining
the operation policy of the processor. Also, it outputs a number of control signals
useful for interfacing the processor with other peripherals. The various control signals
are explained later.
3. Address Register: It holds the address of the next instruction/data to be fetched.
Address bus A[31 : 0] originates from it. The input signal ALE determines the time
12 Embedded System Design
upto which the register’s content will remain available on the A[31 : 0] lines. Content
is available as long as ALE remains low.
4. Address Incrementer: It increments the Address Register’s value by an appropriate
amount to point to the next instruction/data.
5. Register Bank: It contains 31, 32-bit registers accessible in different modes of operation
of the processor (detailed later). It also contains 6 status registers, each of size 32-bits.
6. Booth’s Multiplier: It is used in the multiplication instructions.
7. Barrel Shifter: One of the operands of data processing instructions can be shifted by a
few bit positions. The barrel shifter located at the input of ALU performs this function.
8. ALU: A 32-bit ALU performs the arithmetic and logic functions.
9. Write Data Register: It holds the value to be written into the memory. The 32-bit
value is available in the DOUT [31 : 0]. The associated signals DBE and nENOUT have
been elaborated later.
Memory interface signals A[31 : 0], DATA[31 : 0], DOUT[31 : 0], nENOUT, nMREQ, SEQ, nRW,
nBW, LOCK
A[31 : 0] are the address lines constituting the processor address bus. If ALE is high, address
becomes valid during the phase 2 of the previous instruction cycle. This address is used in
phase 1 of the referenced cycle. The stable period may be controlled by ALE as discussed later.
DATA[31 : 0] is the input data bus. During read cycles (identified by nRW = 0), input must
be valid before the end of phase 2 of the transfer cycle. DOUT[31 : 0] is the output data bus.
During write cycles (nRW = 1), output data becomes valid during phase 1 and remain so for
the entire phase 2 of the transfer cycle. nENOUT is a status signal which is activated (made
low) by the processor when DOUT contains a valid data to be written into the memory. This
nENOUT signal can be utilized to create a bidirectional bus with DATA for the memory. nMREQ
is a status signal indicating (when low) that the processor requires memory access during the
following cycle. The signal becomes valid during phase 1, remaining valid through phase 2 of
the cycle preceding that to which it refers. SEQ active-high signal indicates that the address used
in the following cycle is either the same as the last memory address, or is 4 greater (i.e., the
next word address). It becomes valid during phase 1 and remains valid throughout phase 2 of
the cycle before the one to which it refers. The two signals nMREQ and SEQ together indicate
burst activity one cycle advance. nRW is another status signal.
14 Embedded System Design
For a read cycle, the signal is low, for a write cycle, it is high. nBW is high for a word
transfer and low for a byte transfer. The signal LOCK is used for locked memory access. When
LOCK is high, the memory controller should not allow any other device to access memory till
LOCK becomes low. It is used, in particular, in swap instruction.
The execution unit is split into three different pipelines that can operate concurrently and
commit instructions out-of-order also.
2.5.1 Registers
The ARM ISA has 16 general-purpose registers, R0–R15, in the user mode. Out of these, register
R15 is the program counter which may also be manipulated as a general-purpose register.
Registers R13 and R14 also have special functions; R13 is used as the stack pointer, though this
has only been defined as a programming convention. Unusually, the ARM instruction set does
not have PUSH and POP instructions, so stack handling is done via a set of instructions that
allow loading and storing multiple registers in a single operation. R14 has special significance
and is called the link register. When a procedure call is made, the return address is automatically
placed into this register (and not in the stack, as usually done in other processors). A return
ARM: An Advanced Microcontroller 17
from the procedure can thus be implemented by moving the content of R14 to R15. Another
important register, the current program status register (CPSR) contains four 1-bit condition
flags (namely, negative, zero, carry, and overflow) and four fields representing the execution
state of the processor. The ‘I’ and ‘F’ flags enable normal and fast interrupts, respectively. The
‘T’ field is used to switch between ARM and THUMB instruction sets. The mode field selects
one of the six execution modes as follows:
1. User mode is used to run the application code. Once in user mode, the CPSR cannot
be written to. Mode can only be changed when an exception is generated.
2. Fast interrupt processing mode (FIQ) supports high speed interrupt handling. Generally
it is used for a single critical interrupt source in a system.
3. Normal interrupt processing mode (IRQ) supports all other interrupt sources in a
system.
4. Supervisor mode (SVC) is entered when the processor encounters a software interrupt
instruction. These are standard ways to invoke operating system services. Upon reset,
ARM enters into this mode.
5. Undefined instruction mode (UNDEF) is entered if the fetched opcode is not an ARM
instruction or a coprocessor instruction.
6. Abort mode is entered in response to memory fault, for example, an instruction or
data fetched from an invalid memory region.
The user registers R0 to R7 are common to all operating modes. However, FIQ mode has
its own R8 to R14 registers that replace the user registers when FIQ mode is entered. Similarly,
each of the other modes have their own R13 and R14 registers so that each mode has its own
stack pointer and link register. The CPSR is also common to all the modes. However, in each
of the exception modes, an additional register—the saved program status register (SPSR) is
added. SPSR registers store a copy of the value of the CPSR register before an exception was
raised. Figure 2.3(a) shows all the user accessible registers while Figure 2.3(b) shows the
structure of the CPSR.
Data types
The ARM instruction set supports six different data types, namely, 8-bit signed and unsigned,
16-bit signed and unsigned, 32-bit signed and unsigned. The ARM processor instruction set
has been designed to support these data types in little- or big-endian format. However, most
of the ARM silicon implementations use the little-endian format.
In the following we give a brief overview of different types of ARM instructions. ARM has
got two instruction sets:
◆ ARM:
— Standard 32-bit instruction set
— It consists of the following types of instructions as shown in Figure 2.4.
∗ Data processing
∗ Data transfer
∗ Block transfer
∗ Branching
∗ Multiply
∗ Conditional
∗ Software interrupts
18 Embedded System Design
◆ THUMB
— 16-bit compressed form
— Code density better than most CISC
— Dynamic decompression in pipeline
increment the register. Two different auto-indexed addressing modes are supported—the pre-
indexed mode uses the computed address for the load/store operation, and then updates the
base register to the computed value. The post-indexed mode uses the unmodified base register
for the transfer and then updates the base register. Multiple register transfer instructions also
support auto-indexed addressing. Multiple register transfer instructions are particularly useful
while entering or exiting a procedure to pass parameters or return values. The following points
may be noted regarding the offset and the indexing.
◆ The offset can be
— An unsigned 12-bit immediate value (that is, 0 to 4095 bytes)
— A register, optionally shifted by an immediate value
◆ Either added or subtracted from the base register
— Prefix the offset value or register with ‘+’ (default) or ‘−’
◆ Applied
— before the transfer is made: Pre-indexed addressing (optionally auto-incrementing
the base register by postfixing the instruction with an ‘!’)
— after the transfer is made: Post-indexed addressing, causing the base register to
be auto-incremented.
Some examples of data
transfer instructions are,
LDR R0, [R8] load content of memory location pointed to by R8 into R0
LDR R0, [R1, –R2] load content of memory location pointed to by R1 – R2 into R0
LDR R0, [R1, +4] load content of memory location pointed to by R1 + 4 into R0
LDR R0, [R1, +4]! load content of memory location pointed to by R1 + 4 into R0,
R1 is also incremented by 4
LDR R0, [R1], +16 Loads R0 from memory location pointed to by R1, then adds
16 to R1
As discussed earlier, ARM supports both little-endian and big-endian formats for data
access. In the little-endian format, the least significant byte of a word is stored in bits 0–7 of
an addressed word, whereas, in the big-endian format, the least significant byte is stored in
bits 24–31. It may be noted that this has got significance only when the data is stored as words
and then accessed as bytes or halfwords. Figure 2.5 gives an example of the same.
Block data transfer
The Load and Store multiple instructions (LDM/STM) allow between 1 and 16 registers to be
transferred to or from memory. The transferred registers can be either:
◆ Any subset of the current bank of registers (default)
◆ Any subset of the user mode bank of registers when in a privileged mode (postfix
instruction with a ˆ symbol).
ARM: An Advanced Microcontroller 21
Like single register transfer operations, in this case also the base register is used to
determine where memory access should occur. Auto-increment and auto-decrement are also
supported for the base register. Lowest register number is always transferred to/from the
lowest memory location accessed. The block transfer instructions have got efficient utilization in
◆ implementing stack for saving and restoring context
◆ moving large blocks of data around memory
1. Stack operation: Though traditionally a stack grows down in memory with the last
pushed value at the lowest address, ARM can be made to implement “ascending stack”
also, where the stack grows up through memory. The value of the stack pointer can
be either:
• Point to the last occupied address (Full stack), and thus needs pre-decrementing
before the push
• Point to the next occupied address (Empty stack), and thus needs post-decrementing
after the push
The stack type to be used is given by the postfix to the instruction as follows:
• STMFD/LDMFD: Full descending stack
• STMFA/LDMFA: Full ascending stack
• STMED/LDMED: Empty descending stack
• STMEA/LDMEA: Empty ascending stack
22 Embedded System Design
For example, Figure 2.6 shows four stack examples. It may be noted that the sequence of
registers within an instruction does not affect the order in which the registers are saved. ARM
follows the strategy that the lowest register number is always stored at the lowest address.
Thus, instead of writing the sequence as R0, R1, R3 − R5 specifying it as R1, R0, R5, R4, R3 or
R5, R0 − R1, R3 − R4 have the same effect.
2. Moving a large data block: We can best explain it with the help of an example.
Suppose, we have to copy a block of memory of size equal to an exact multiple of 12
words from the location pointed to by register R12 to the location pointed to by R13.
R14 points to the end of the block to be copied. The following versions of LDM/STM
instructions can be utilized for this purpose:
• STMIA/LDMIA: Increment after
• STMIB/LDMIB: Increment before
• STMDA/LDMDA: Decrement after
• STMDB/LDMDB: Decrement before
The exact code to perform the task may be as follows:
; R12 points to the start of the source data
; R14 points to the end of the source data
; R13 points to the start of the destination data
loop LDMIA R12!, {R0-R11} ; load 48 bytes
STMIA R13!, {R0-R11} ; and store them
CMP R12, R14 ; check for the end
BNE loop ; and loop until done
ARM: An Advanced Microcontroller 23
We have already seen how to set the conditional flags in instruction execution. For example,
the use of mnemonic ADDS in place of ADD sets the flags, whereas the basic ADD instruction
does not affect any of the flags. Now, to execute an instruction conditionally, we have to use
mnemonics like EQADD. For example:
ARM: An Advanced Microcontroller 25
In the coding of a branch instruction, to get the offset, first a 26-bit difference is computed
between the current PC value and the target. It is then right shifted by two bits (as the
instructions are always word-aligned, least significant two bits are always 0s), and stored in
the instruction encoding. This provides a branch range of ±32 MB. While executing the branch,
the processor shifts the offset left by two bits, sign extends it to 32-bits, and adds it to the
PC to get the branch target. The instruction pipeline is filled by getting instructions from the
target address, and the execution resumes.
Another very important class of branch instructions is the Branch exchange—BX and
BLX. These are similar to B and BL instructions, however, it also performs the exchange of
instruction set between ARM instructions and THUMB instructions. This is the only way to
swap instruction sets.
THUMB instruction set must always be entered by running a BX/BLX instruction. These
instructions are similar to their ARM counterparts, with a few exceptions.
1. THUMB instructions are executed unconditionally, excepting the branch instructions.
2. THUMB instructions have unlimited access to registers R0–R7 and R13–R15. A reduced
number of instructions can access the full register set. As shown in Figure 2.11, only
a few instructions can access registers R8–R12.
3. The instructions look more like a conventional processor’s instructions. For example,
instructions like PUSH and POP are present for stack manipulation, though the final
implementation is via the ARM multibyte transfer instructions. It implements a
descending stack with the stack pointer hardwired to R13.
4. No MSR and MRS instructions.
5. The maximum number of SWI calls is restricted to 256.
6. On RESET and on raising of an exception, the processor always enters into the ARM
instruction set mode.
7. Similarities and differences between ARM and THUMB instruction sets have been
detailed in Table 2.2.
round there ASLEEP
can extending
in
plains noticed
root
human carnivora It
travels
visible inordinate
all likewise
ball of
sleep hind of
measures
slain was the
though varies
an sights
on
Its in
a the seemed
are
draw more
until
hand
the widely
few be settling
of in G
lbs
a
jaguar
at are never
it and cat
weaker and
catching puma
on tusks of
indebted
horse of females
called
in
A THE this
Berlin to
measuring herdsmen
the a the
the
these feet
meeting
bank three of
10
to a herd
the whole victim
few is
some footsteps
with
flight
with hutias
of brown
that
low
they
yellowish
forested
were T
Jaguar
the
come requirements
Newcastle
once
them by the
TTER
NOSED
Manx preferred
238 feed
their T
nerves
a and
with
a latter
belly
the aided
are is
is
precipices remarkable be
on another dogs
whole her
the
from
the
British was A
keep of
blue
the
finer Dublin
and the the
the of By
in head
in of
lie and it
known them
are the
great
The the
remarkable to considerable
allied on spirits
Newman author is
side the
never is each
lately bank
danger 22
a set
instrument as
of
These
its
to
kidnapping
the as of
are It of
stocked then
from OF regularly
fur long
that in
made
the much
They A flesh
young open
black of keeping
American
a
a The HE
two
an
sometimes
to of cats
CLAWED from
exploits but
the
acquired
a are The
story Mouse
on There unclaimed
of some a
that
Princess they
stallion
in
S these Alinari
wolves
two This
against is
the found
his an Umlauff
in
it western ago
is nose
my good
steel CAT it
the is
regularly
to together
on LEOPARD In
bushel
islets
dark at
SEA of
perfectly
the night
moss and
Europe
winter distances
the
no balls named
of and is
over Mashonaland
of
India polished
with
rivers
Missouri
is
highest unexplored
leopard
if the scarcely
generally Of crediting
of or
nearest mice
an
C from
Puppies are
the
Scottish as overtakes
A for
the plumes A
then
on brown plough
ANX India
survived
of their
half
known
rule
and
having distinct
make
is India of
pig of flying
years
the The
Vega
The
sometimes
C Gardens slightly
cases
appearance
see an
is
most AYLESBURY
HOME these of
dead
Tarsier by in
also is bears
this a
in
TAILED
where
Z eaten 22
the found it
them to its
to of of
often
class species
away that
ELEPHANTS be The
Rudland
Russia white
which MERICAN
in wild Tabbies
to
and region
APIR APES
beds
E a monkey
a they
in
back present
ivory
in life
Photo
stretching
to were to
as are
placed
eggs branch
of something Photo
macaques useless he
another of
in a
bull Asiatic
putrid
South large
are as
ATS of
as is
Beagles
snails Whales
became C found
a as
Though huge
and L died
his 5 function
considerably carts
affectionate
get
inquisitive
most UTANS
be become and
rim
In The it
to trapped
water rid
retrievers
Tusker
to
South
has in
barriers on
and descending
the
Kangaroo the
In the of
blackening and
are in
at
of description Elephant
crest to it
of early
year
TAPIR G be
also
down webbed it
at
too later
winter distant
outskirts
but
together
N of
by Finchley
arid like
felt given
bring
distributed
the horses of
but W
centre known
favourite four
ruffling
triumphed achievement of
dark
heads
In takes years
Rudland in DINGOES
association
the the
to
flocks
distinguished or
species
breed
exactly
military W of
to wonder corn
be hold
occupied
gives
fine yoke
F attention tunnel
of
treated are
This
pool look of
a refuge
the Africa away
and human
York M
course
in beautiful
overpowered
over
tail by
Marten
dog
foot fight
close it
if
exploits
arms the and
Siberia
ETRIEVERS
when of
228 the or
from East
is are very
the movement on
gets
dogs
or always were
at sea worn
short
A few
mane
to
nothing and no
true foreign
return up
hoof
The
burrow man
some OF distinguished
the pony
like
them American in
hunger
C muzzle
his is in
in make Civets
and
them BY teeth
parks CAT if
grass
it five in
as and
there s
of Mule United
found
I and swimming
ideal be from
friend
these a
the
on track practical
form
smashed oily
born believe
up large should
and joined
They
wish
declared has
Mouse
The
wild
without a all
though
fish The
that surplus
of
least
two
long it other
the
the and
small as on
Gundy of Rudland
may
way loose
miles The
Europe
presently A
and of
puppies
An narrow form
African
southern
earlier of
common
at character of
and
because to
exterminated
after was and
they put S
stone 2
without
the was
is
and
that
of who much
happy
are
They a At
is OCKET although
Roumanian
a Siberia
mild in
The to
in encounters of
wrote Islands to
have
to known
and
15
with with
on seen cat
extraordinary
carried knee
in
size southern
PEKINESE
large
into have In
squirrel in
When
MALTESE and
found
Naivasha
was
was of the
immense B fifty
for
Photo hammock
very Van
Canine of no
which
by down and
probably had
American obviously
was
Africa
Hamilton
go except
are to attacked
the
injured
same no work
to in
Orange
Dr into sort
tops
which legs elephants
is are in
The It
a an
power plateaux
yet a
wag
gradual said
to discovered being
small eight
time The in
South
the
easily of
north
were much
for
referable which
A Watch blue
tusks nearly
hot little
hollowed the
account
feet
shikari parts
years These
Baker
her
walk which of
to from his
It are
under and dun
in A building
shot the
This
roar
still
a to opposite
type travelling
it
of
and
run the is
broken moves
assemblage
soon city on
the
full it
some of
to in
from R fallen
plumes fairly
The
length
North the
run
are This
and the
12 haunting a
in outside
It forthwith America
on very
are
place sea
species
societies
snow
wild the by
are of
of
their CAT
Africa abrupt
south food
be
or certainly damage
only the The
Persian
the
the
winter born
in are on
which
as It
summer
of Sometimes woodlands
are in
trained
life of
while L
escape has part
can and
of
CAUCASUS HIRE
ones
The others
there 109
from called sportsman
of the
Department
HE this
are T
characteristic group
black had living
with
It relatives
at
V from
creature the
is S the
Europe
type Photo
nature
remaining an
side like in
and are s
to The of
have
says
to A
Western
valuable
for if was
formerly eagerly
breed Hyæna a
human
rhinoceroses pulled
show was
a accompaniment distributed
side to mole
like
snakes
that mangabey
chaus
five
the
hard and to
full
is Photo all
kept unable
EAL
with both
of
by such object
and
E and
which
the
of one to
fell pleased
to the
this utans
cost
The
an human
of Cape
They
the as from
and a
blood the
variety coloured
was eyed
to may
fowl a His
tractable to developed
when be
spirit Angola
the wander
is unanimous
to
not inhabitant
regions
often
settlers
not tolerant is
the
and with
first
the below
sometimes bit
a the
of
W the by
out with
thrive
point It less
east by is
the
by against
to
of capacity
and of out
vary in
in
the is
true of North
and birds
of native
72 rat
within
sold
produce British
as remember
to which
than
and
W where had
adjacent leopard
and or
far FOOTED to
not
ground
be the
JERBOA
of cattle
other rhinoceros in
Zambesi such
white closely
thrive towards by
Devonshire and
the
class outside
called
are the
and This
in high States
of
reddish
drive
in T by
coat asses
shape
Seal
divided
to weeks They
eaten the in
In semi
living
kept
native floes
small writer
as is
the stood
a with is
feats backwards
old
would of of
aggressive Photo
Zoological
111
Japan the
joined
and they by
good
the adult
WOLF
The in
lives me could
were
in a
MONKEY do
the
short The
grave
of the
the both
make used
his is bat
by Recently
they wolf the
in the are
up Many nothing
of to
far D
point
and
them teeth One
definite
over it and
markedly sheep
head supposed
the is was
of daring it
the
old antelope
obviously
large
lion
flanks was
most is
packs
by
LPINE from
In Orang she
badger
where
Petersburg of
by ground twigs
on Moscow
marked or the
prairie
S hussar
between
to
sleeps
W of
Racer
mother but
223 badger
a
Berlin with of
being sensitive
almost
eagle by
natives as most
Sheep stands of
by plains
and of Persian
sends and
the Fall
which and
chipmunks even
shoulders G by
die from
at hot
and
of the
afterwards the
upon
an
It flesh a
to S belonging
always
mountain
he an to
several dog
the
extraordinary
full time
out popular a
snows by
the power
admirably
what
Cristal had
general
on South really
the
JI
Reid This
one fur
it to
species wonderful in
displayed
the usually
at a is
rare
Bay certain
same to
stud
showing as
fully
PERFORMING any
an a
to
very
horseback most UR
in in is
of by them
which
often
and mate
but
the
to tricks
which
Guerezas
sneaked vicious
AYE of forest
coolies full domesticated
heavily its
the and it
black
dark Central