Embedded Systems
Embedded Systems
By
Dr. H Manas Singh
Department of ECE
IIIT Manipur
INTRODUCTION TO EMBEDDED
SYSTEM
What are embedded systems?
• Computers embedded within other systems
Figure: Microprocessor
Figure: Microprocessor
MACHINE LANGUAGE
• Each microprocessor has its own binary words, meanings, and language.
• The word (or word length) is defined as the number of bits the
microprocessor recognizes and process at a time.
• To communicate with computer, one must give instructions in binary
language (machine language).
• The number of bits that form the word of a microprocessor is fixed for that
particular processor.
• For example, an 8-bit microprocessor can have at most 256 different
combinations.
• Each of these patterns forms an instruction for the microprocessor.
• The complete set of patterns makes up the microprocessor’s machine
language.
Microcontroller
• A microcontroller (µC) is a small computer on a single integrated
circuit consisting of a central processing unit (CPU) combined with
peripheral devices such as memories, I/O devices, and timers as well
as ADC’s.
• An 8-bit µC is designed for low-cost applications and includes on-board
memory and I/O devices.
• A 16-bit µC is often used for more sophisticated applications that may require
either longer word lengths or off-chip I/O and memory
• A 32-bit RISC µP offers very high performance for computation-intensive
applications.
How to distinguish between microcontroller
and general-purpose processors?
• Microcontrollers are generally associated with the embedded applications.
• Microprocessors are associated with the desktop computers.
• Microcontrollers will have simpler memory hierarchy i.e. the RAM and
ROM may exist on the same chip and generally the cache memory will be
absent.
• The power consumption and temperature rise of µC is restricted because
of the constraints on the physical dimensions.
• 8-bit and 16-bit microcontrollers are very popular with a simpler design as
compared to large bit-length (32-bit, 64-bit) complex general purpose
processors.
Figure. Performance vs cost regions
Figure: Microprocessor-based system
Figure: Microcontroller-based system
Microprocessor Microcontroller
Microprocessors are multitasking in nature. Single task oriented. For example, a washing
Can perform multiple tasks at a time. For machine is designed for washing clothes only.
example, on computer we can play music while
writing text in text editor.
RAM, ROM, I/O Ports, and Timers can be RAM, ROM, I/O Ports, and Timers cannot be
added externally and can vary in numbers. added externally. These components are to be
embedded together on a chip and are fixed in
numbers.
Designers can decide the number of memory Fixed number for memory or I/O makes a
or I/O ports needed. microcontroller ideal for a limited but specific
task.
External support of external memory and I/O Microcontrollers are lightweight and cheaper
ports makes a microprocessor-based system than a microprocessor.
heavier and costlier.
External devices require more space and their A microcontroller-based system consumes less
power consumption is higher. power and takes less space.
CISC (8051) and RISC (ARM) architectures
• A microcontrollers (µC’s) with Harvard architecture are called “RISC
µC’s”.
• µC’s with von-Neumann’s architecture are called “CISC µC’s”.
Von Neumann Architecture
Many addressing modes causing complex Few addressing modes, fix instruction
instruction formats. format.
• The label field allows the program to refer to a line of code by name.
The label fields cannot exceed a certain number of characters.
• The mnemonics and operands fields together perform the real work
of the program and accomplish the tasks.
Embedded Systems - Assembly Language
Assembling and Running an 8051 Program:
Editor program
1. First, we use an editor to type in a program similar
to the above program. The Editor must be able to
produce an ASCII file. The "asm" extension for the .asm
source file is used by an assembler in the next step. assembler
2. The "asm" source file contains the program code program
created in Step 1. It is fed to an 8051 assembler
which produces an .obj file (object file) and a .lst file .obj & .lst
(list file). It is also called as a source file.
3. Assemblers require a third step called linking. The linker program
link program takes one or more object files and
produces an absolute object file with the extension
"abs".
.abs
4. Next, the "abs" file is fed to a program called "OH"
(object to hex converter), which creates a file with
the extension "hex" that is ready to burn in to the 0H program
ROM.
.hex
Why Use HEX Files in Embedded Systems?
▪ Error Detection:
• The checksum ensures data integrity during transmission or loading.
▪ Human Readability:
• Unlike binary files, HEX files can be inspected and debugged manually.
▪ Ease of Parsing:
• Programming tools and bootloaders can easily parse the structured format.
▪ Target Compatibility:
• Memory addresses in HEX files ensure the firmware is loaded into the correct
locations in the target device.
Data Type
• The 8051 microcontroller contains a single data type of 8-bits, and
each register is also of 8-bits size.
• The programmer has to break down data larger than 8-bits (00 to
FFH, or to 255 in decimal) so that it can be processed by the CPU.
▪ DB (Define Byte):
• The DB directive is the most widely used data directive in the assembler.
• It is used to define the 8-bit data.
• It can also be used to define decimal, binary, hex, or ASCII formats data.
• For decimal, the "D" after the decimal number is optional, but it is required
for "B" (binary) and "H" (hexadecimal).
Assembler Directives
• Some of the directives of 8051 are as follows:
1. ORG (origin):
• The origin directive is used to indicate the beginning of the address.
• It takes the numbers in hexa or decimal format.
2. EQU (equate)
• It is used to define a constant without occupying a memory location.
• EQU associates a constant value with a data label so that the label appears in the
program, its constant value will be substituted for the label.
3. END directive:
• It indicates the end of the source (asm) file.
• The END directive is the last line of the program; anything after the END directive is
ignored by the assembler.
Embedded Systems - Registers
• Registers are used in the CPU to store information on temporarily
basis which could be data to be processed, or an address pointing to
the data which is to be fetched.
• In 8051, there is one data type of 8-bits.
• The most widely used registers of the 8051 are A (accumulator), B,
R0-R7, DPTR (data pointer), and PC(program counter).
Storage Registers in 8051
• Accumulator
• Data Pointer (DPTR)
• B register
• Program Counter (PC)
• R register (R0 – R7)
• Stack Pointer (SP)
Storage Registers in 8051
▪ Accumulator:
• The accumulator, register A, is used for all arithmetic and logic
operations.
• If the accumulator is not present, then every result of each
calculation (addition, multiplication, shift, etc.) is to be stored into the
main memory.
▪ The "R" Registers
• The "R" registers are a set of eight registers, namely, R0, R1 to R7.
• These registers function as auxiliary or temporary storage registers in
many operations.
Storage Registers in 8051
▪ The "B" Register:
• The "B" register is very similar to the Accumulator in the sense that it
may hold an 8bit(1-byte) value.
• The "B" register is used only by two 8051 instructions: MUL AB and
DIV AB.
▪ The Data Pointer:
• The Data Pointer (DPTR) is the 8051’s only user-accessible 16-bit (2-
byte) register.
• It is used by the 8051 to access external memory using the address
indicated by DPTR.
Storage Registers in 8051
▪ The Program Counter:
• The Program Counter (PC) is a 2-byte address which tells the 8051
where the next instruction to execute can be found in the memory.
▪ The Stack Pointer (SP):
• The Stack Pointer, like all registers except DPTR and PC, may hold an
8-bit (1-byte) value.
• The Stack Pointer tells the location from where the next value is to be
removed from the stack.
Embedded Systems - Addressing Modes
▪ An addressing mode refers to how you are addressing a given
memory location. There are five different ways or five addressing
modes to execute this instruction which are as follows −
• Immediate addressing mode
• Direct addressing mode
• Register direct addressing mode
• Register indirect addressing mode
• Indexed addressing mode
Embedded Systems - Addressing Modes
▪ Immediate Addressing Mode:
Embedded Systems - Addressing Modes
▪ Direct Addressing Mode:
Here, the address of the data (source data) is given as an operand.
Embedded Systems - Addressing Modes
▪ Register Direct Addressing Mode:
• In this addressing mode, we use the register name directly (as source
operand). Instruction Opcode Bytes Cycles
MOV A, R4 ECH 1 1
Embedded Systems - Addressing Modes
▪ Register Indirect Addressing Mode:
• In this addressing mode, the address of the data is stored in the
register as operand.
Interrupt
Reset
Undefined
Software
Prefetch request
Data vector
abort
abort is the
interrupt vector
location
instruction
vector
vector is used
isvector
similar
vector
occurs of isthe
istowhen by external
first
called
aused
prefetch
when
when
the hardware
instruction
abort
the
youprocessor
processorbut
execute to interrupt
executed a by
is raised
attempts cannot
SWIthe
when
to the normal
processor
instruction.
decode
fetch execution
when
ananinstruction power
an instruction.
The attempts
instructionSWI flow
isto of theis
applied.
frominstruction
an access
address
processor.
This theItused
frequently
withoutmemory can
datainstruction only
branches
without
as the
correct bethe
raised
theifinitialization
topermissions.
mechanism
access correct IRQs are
access notactual
to invoke masked
code.
permissions.
The an in the
operating
abort cpsr.in routine.
system
occurs the decode stage.
Core Extensions
• Placed next to the ARM Core.
• Improve performance, manage resources, and provide extra functionality and
are designed to provide flexibility in handling particular applications.
• Three hardware extensions ARM wraps around the core:
• cache and tightly coupled memory
• memory management
• the coprocessor interface.
• Cache and Tightly Coupled Memory
• The cache is a block of fast memory placed between main memory and the
core.
• Most ARM-based embedded systems use a single-level cache internal to the
processor.
Core Extensions - Cache and Tightly Coupled
Memory
x—family
y—memory management/protection unit
z—cache
T—Thumb 16-bit decoder
D—JTAG debug
M—fast multiplier
I—EmbeddedICE macrocell
E—enhanced instructions
J—Jazelle
F—vector floating-point unit
S—synthesizible version
Description of the cpsr
ARM family attribute comparison
ARM processor variants.
Summary
• The ARM processor can be abstracted into eight components—ALU,
barrel shifter, MAC, register file, instruction decoder, address register,
incrementer, and sign extend.
• ARM has three instruction sets—ARM, Thumb, and Jazelle.
• The register file contains 37 registers, but only 17 or 18 registers are
accessible at any point in time; the rest are banked according to
processor mode.
• The current processor mode is stored in the cpsr.
• It holds the current status of the processor core as well interrupt masks,
condition flags, and state. The state determines which instruction set is being
executed.
Summary
• An ARM processor comprises a core plus the surrounding components that
interface it with a bus. The core extensions include the following:
• Caches are used to improve the overall system performance.
• TCMs are used to improve deterministic real-time response.
• Memory management is used to organize memory and protect system resources.
• Coprocessors are used to extend the instruction set and functionality. Coprocessor
15 controls the cache, TCMs, and memory management.
• An ARM processor is an implementation of a specific instruction set
architecture (ISA).
• Processors are grouped into implementation families (ARM7, ARM9,
ARM10, and ARM11) with similar characteristics.
INTRODUCTION TO THE ARM
INSTRUCTION SET
The ARM Instruction Set
• ARM instructions process data held in registers and only
access memory with load and store instructions.
The ARM Instruction Set
• ARM instructions commonly take two or three operands.
*The C flag is updated in the cpsr because the S suffix is present in the instruction mnemonic.
Arithmetic Instructions
• The arithmetic instructions implement addition and subtraction of 32-
bit signed and unsigned values.
Register r1 is first shifted one location to the left to give the value of twice r1.
Logical Instructions
• Logical instructions perform bitwise logical operations on the two
source registers.
Logical Instructions
logical OR operation between registers r1 and r2
• Similarly the TST instruction is a logical AND operation, and TEQ is a logical
exclusive OR operation.
• It is important to understand that comparison instructions only modify the
condition flags of the cpsr and do not affect the registers being compared.
Multiply Instructions
• The multiply instructions multiply the contents of a pair of registers and,
depending upon the instruction, accumulate the results in with another register.
• The address label is stored in the instruction as a signed pc-relative offset and must be
within approximately 32 MB of the branch instruction.
Branch Instructions
• The forward branch skips three instructions.
• The backward branch creates an infinite loop.
✓ Most assemblers hide the details of a branch instruction encoding by using labels.
✓ The branch labels are placed at the beginning of the line and are used to mark an address
that can be used later by the assembler to calculate the branch offset.
Branch Instructions
• The branch with link, or BL, instruction is similar to the B instruction
but overwrites the link register lr with a return address.
• It performs a subroutine call.
✓ The branch exchange (BX) and branch exchange with link (BLX) are the third type of
branch instruction.
✓ The BX instruction uses an absolute address stored in register Rm. It is primarily used to
branch to and from Thumb code
Load-Store Instructions
• Load-store instructions transfer data between memory and processor
registers.
• There are three types of load-store instructions:
• single-register transfer
• multiple-register transfer
• swap
Load-Store Instructions
▪ Single-Register Transfer
• These instructions are used for moving a single data item in and out
of a register.
• The datatypes supported are signed and unsigned words (32-bit),
halfwords (16-bit), and bytes.
Load-Store Instructions
Loads a word from the address stored in register r1 and Stores the contents of register r0 to the address contained
places it into register r0. in register r1.
The offset from register r1 is zero
Register r1 is called the base address register.
Single-Register Load-Store Addressing Modes
Index methods
• Preindex with writeback calculates an address from a base register plus address
offset and then updates that address base register with the new address.
• The preindex offset is the same as the preindex with writeback but does not
update the address base register.
• Postindex only updates the address base register after the address is used.
Single-Register Load-Store Addressing Modes
• The preindex mode is useful for accessing an element in a data
structure.
• The postindex and preindex with writeback modes are useful for
traversing an array.
Single-Register Load-Store Addressing Modes
Single-Register Load-Store Addressing Modes
Single-register load-store addressing, word or unsigned byte
• A signed offset or register is denoted by “+/”,identifying that it is either a positive or negative offset from the
base address register Rn.
• The base address register is a pointer to a byte in memory, and the offset specifies a number of bytes.
• Immediate means the address is calculated using the base address register and a 12-bit offset encoded in the
instruction.
• Register means the address is calculated using the base address register and a specific register’s contents.
• Scaled means the address is calculated using the base address register and a barrel shift operation.
Single-Register Load-Store Addressing Modes
Examples of LDR instructions using different addressing modes.
Single-Register Load-Store Addressing Modes
Single-register load-store addressing, halfword, signed halfword, signed byte, and doubleword.
Single-Register Load-Store Addressing Modes
Variations of STRH instructions.
Multiple-Register Transfer
• Load-store multiple instructions can transfer multiple registers
between memory and the processor in a single instruction.
• The transfer occurs from a base address register Rn pointing into
memory.
• Multiple-register transfer instructions are more efficient from single-
register transfers for moving blocks of data around memory and
saving and restoring context and stacks.
• Load-store multiple instructions can increase interrupt latency.
Multiple-Register Transfer
• Any subset of the current bank of registers can be transferred to memory or fetched from memory.
• The base register Rn determines the source or destination address for a load-store multiple
instruction.
• This register can be optionally updated following the transfer.
• This occurs when register Rn is followed by the ! character, similar to the single-register load-
store using preindex with writeback.
Multiple-Register Transfer
Addressing mode for load-store multiple instructions.
Swap Instruction
• The swap instruction is a special case of a load-store instruction.
• It swaps the contents of memory with the contents of a register.
• This instruction is an atomic operation—it reads and writes a
location in the same bus operation, preventing any other instruction
from reading or writing to that location until it completes.
• Swap cannot be interrupted by any other instruction or any other bus
access.
• The system “holds the bus” until the transaction is complete.
Swap Instruction
Swap Instruction
Software Interrupt Instruction
• A software interrupt instruction (SWI) causes a software interrupt
exception, which provides a mechanism for applications to call
operating system routines.
• When the processor executes an SWI instruction, it sets the program
counter pc to the offset 0x8 in the vector table.
• The instruction also forces the processor mode to SVC
Software Interrupt Instruction
Typically the SWI instruction is executed in user mode.
• Code called the SWI handler is required to process the SWI call. The handler obtains the SWI number
using the address of the executed instruction, which is calculated from the link register lr.
• The SWI number is determined by
Here the SWI instruction is the actual 32-bit SWI instruction executed by the processor.
Software Interrupt Instruction
Program Status Register Instructions
• The ARM instruction set provides two instructions to directly control
a program status register (psr).
• The MRS instruction transfers the contents of either the cpsr or spsr
into a register; in the reverse direction, the MSR instruction transfers
the contents of a register into the cpsr or spsr.
• These instructions are used to read and write the cpsr and spsr.
fields: This can be any combination of control (c), extension (x), status (s), and
flags (f ). These fields relate to particular byte regions in a psr.
Program Status Register Instructions
The c field controls the interrupt masks, Thumb state, and processor mode.
Program Status Register Instructions
SVC mode
In user mode you can read all cpsr bits, but you can only update the condition flag
field f.
Bus-Based Computer Systems
• The bus is the mechanism by which the CPU communicates with
memory and I/O devices.
• A bus is a collection wires with a defined protocols by which the CPU,
memory, and devices communicate.
• Bus Protocols: Controls communication between entities.
• Determines who gets to use the bus at any particular time.
• Governs length, style of communication.
CPU Bus
• Device 1 raises its output to signal an enquiry, which tells device 2
that it should get ready to listen for data.
• When device 2 is ready to receive, it raises its output to signal an
acknowledgment. At this point, devices 1 and 2 can transmit or
receive.
• Once the data transfer is complete, device 2 lowers its output,
signaling that it has received the data.
• After seeing that ack has been released, device 1 lowers its output.
CPU Bus
• The fundamental bus operations are reading and writing.
• The major components are:
• Clock provides synchronization to the bus components,
• R/𝑾 is true when the bus is reading and false when the bus is writing,
• Address is an n-bit bundle of signals that transmits the address for an access,
• Data is an n-bit bundle of signals that can carry data to or from the CPU, and
• Data ready signals when the values on the data bundle are valid.
CPU Bus
If the CPU scheduling policy is Round Robin with time quantum = 2 unit,
calculate the average waiting time and average turn around time.
Round Robin Scheduling-
• It leads to starvation for processes with larger burst time as they have to
repeat the cycle many times.
• Its performance heavily depends on time quantum.
• Priorities can not be set for the processes.
Scheduling Algorithms - Round-Robin
Scheduling
• Round-robin scheduling provides each task an equal share of the CPU
execution time.
• Pure round-robin scheduling cannot satisfy real-time system
requirements because in real-time systems, tasks perform work of
varying degrees of importance.
• A priority-based scheduling can be augmented with round-robin
scheduling which uses time slicing to achieve equal allocation of the
CPU for tasks of the same priority.
Scheduling Algorithms - Round-Robin
Scheduling