Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Embedded System:
▪ Normally the primary memory, central
processing unit and many peripheral
components including ADCs are housed on a
single chip.
▪ These chips are also called micro-controllers.
▪ All the units typically operate on same voltage,
like 5V.
PC v.s Micro-controllers
• and 𝑏𝑖 is 0 or 1
This is an excellent representation for digital systems, but poor for us to
use. Why?
• Hint: Quick, what is 1001011110102? Bigger than 100? 1,000? 10,000?
Better choice for people:
OCTAL (23 ) or HEXADECIMAL (or HEX) (24 )
Just a grouping of binary bits into groups of 3 or 4 bits.
Straightforward for people to deal with. Why?
One-to-one representation of what’s happening inside the circuit.
Number Systems….
4572
97A
6
8
Number Systems….
ARM Instruction Set Architecture
▪ Historically, the ARM processors have supported
two different instruction sets:
▪ ARM instructions that are 32 bit
▪ Thumb instructions that are 16 bits.
▪ The size of an instruction (i.e., assembly instruction)
signifies the number of bits required to store the
machine code or opcode of that instruction.
▪ Using Thumb instructions can provide higher code
density.
▪ On the other hand, using ARM instructions can
improve the processor execution performance.
ARM Instruction Set Architecture
▪ Consider a simple user program that involves six
operations to be performed of which three are
simple operations, while the other three are
complex operations.
▪ The three simple operations are supported by both
Thumb as well as ARM instruction set architectures
using three assembly instructions.
▪ On the other hand, the three complex operations
are supported by ARM instruction set and there are
three corresponding assembly instructions.
▪ However, the Thumb instruction set supports these
complex operations by using two assembly
instructions for each of these complex operations.
ARM Instruction Set Architecture
▪ We assume that each of the assembly instructions
used by the program requires one cycle for
execution. Now for the same clock speed, the ARM
ISA based processor will require six clock cycles for
execution, while it will require nine clock cycles for
a Thumb based processor.
▪ On the other hand, it will require 24 bytes(4*6) of
memory space to store the program for ARM ISA
based processor, while 18 bytes (2*(3+6)) will be
required by the Thumb ISA based processor.
▪ This simple example illustrates why ARM ISA has, in
general, better execution performance, while
Thumb ISA has higher code density
ARM and Thumb Instruction
• Thumb2 is a superset of the Thumb instruction set. Thumb2
introduces 32-bit instructions that are intermixed with the 16-bit
instructions. The Thumb2 instruction set covers all the functionality
of the Thumb instruction set.
• Thumb2 has the execution performance close to that of the ARM
instruction set and has the code density performance close to the
original Thumb Instruction Set Architecture (ISA).
• TheThumb2 technology extended the Thumb ISA into a highly code
density efficient and yet powerful instruction set that delivers
significant benefits in terms of ease of use, code size, and
performance.
Register Set
▪ Processor registers are one of the most important
components of a microprocessor core. The
registers can be differentiated based on their
functionality.
✓General-purpose registers, R0-R12
✓Stack Pointer (SP):
✓Link Register (LR):
✓Program Counter (PC):
✓Program Status Registers (PSRs):
✓Control register (CONTROL):
Register Set
Register Set
▪ General-purpose registers, R0-
R12
1. Registers R0-R7 are called low
registers and are accessible by all
instructions that specify a
general-purpose register
2. Registers R8-R12 are called high
registers and are accessible by all
32-bit instructions that specify a
general-purpose register.
Registers R8-R12 are not
accessible by any Thumb (16-bit)
instructions.
Register Set
▪ Stack Pointer (SP):
▪ Register R13 is used as the Stack Pointer (SP). A stack pointer
is a small register that stores the address of the last
program request in a stack. A stack is a specialized buffer
which stores data from the top down.
▪ In addition, it is important to remember that stack pointer is
a banked register with two copies, namely Main Stack
Pointer (MSP) and Process Stack Pointer (PSP).
▪ The Main Stack Pointer (MSP) is the default Stack Pointer
after reset, and is used when running exception handlers.
The Process Stack Pointer (PSP) can only be used in Thread
mode (when not handling exceptions)
▪ Only one copy of the stack pointer (R13) is visible and active
at a given time. This means that stack pointer logically has
one copy at any arbitrary time instant, while physically it has
always two copies.
Register Set
▪ Program Counter (PC):
▪ Register R15 is called the program counter register.
▪ PC contains the current program or instruction address that is to be
executed. This register can be modified by the program itself to control the
flow of the program.
▪ Bit 0 of this register is always 0, which ensures that the instructions are always
aligned to either word or halfword boundaries in the code memory .The usage
and allocation of general-purpose registers in the execution of a specific task
can be performed either automatically by the compiler or manually by writing
an assembly program.
▪ Link Register (LR):
▪ Register R14 is the subroutine Link Register (LR). The LR receives the return
address from the program counter register.
▪ A link register is a special-purpose register which holds the address to return
to when a function call completes.
▪ The link register contains the return address to be used by the processor,
when returning from a function or service routine.
▪ When the link register is not used for holding a return address, it can be
treated as a general-purpose register.
Register Set
▪ Processor registers are one of the most important
components of a microprocessor core. The
registers can be differentiated based on their
functionality.
✓General-purpose registers, R0-R12
✓Stack Pointer (SP):
✓Link Register (LR):
✓Program Counter (PC):
✓Program Status Registers (PSRs):
✓Control register (CONTROL):
Memory Organization
▪ When we refer to memory locations by
address, we only do so in units of bytes,
halfwords or words
▪ • Words
▪ 32 bits = 4 bytes = 1 word = 2 halfwords
▪ In diagram to right, we have two words:
▪ At addresses 0x20000000 and
0x20000004
▪ – Can you store a word/halfword
anywhere?
▪ NO.
▪ A word can only be stored at an address
that's divisible by 4. A halfword is stored
at an address that’s divisible by 2.
▪ Memory address of a word/halfword is
the lowest address of all four/two bytes
in that word.
Endianness
▪ Big Endian:
▪ address of most significant byte = word
address
▪ Little Endian:
▪ address of least significant byte = word
address
▪ ARM is Little Endian by default.
Little Address, Little Byte
▪ One hex digit takes how many bits to
store? 4
ARM Instructions, Major Groups
▪ Data Movement
▪ Load
▪ Store
▪ Move
▪Cortex-M assembly programming ▪ Arithmetic and Logic
multiple assembly instructions can ▪ Add and Subtract
be divided into following groups ▪ Multiply and Divide
▪ Shift and Rotate
▪ Compare and Branch
▪ Compare, Test
▪ Branch
▪ Miscellaneous
▪ Wait for events
▪ Interrupts
▪ Many others
ARM Assembly Language