Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction/The ARM7TDMI
Programmers Model
2
MEMORY SYSTEM
The computer memory hierarchy consists of
several levels, each level being characterized by
size, speed and cost.
Processor
Control
Hard disk
Main (Virtual
Register
Cache
5
THE PROCESSOR (ARM7TDMI)
ARM 7
Thumb
On-chip
Debug
Multiplier
Embedded
ICE ( In-
Circuit
Emulation)
6
DATA TYPES
Data in digital systems is represented by binary
digits called bits
Bits can be imagined as either ON or OFF ( ONE or ZERO)
Byte eight bits grouped together (in most systems)
Halfword two bytes or 16 bits
Word - four bytes or 32 bits ( in ARM cores)
8
PROCESSOR MODES
Version 4T (ARM7TDMI) cores support seven
processor modes: User, FIQ, IRQ , Supervisor,
Abort, Undef, and System.
Mode Description
Supervisor Entered on reset and when a Software Interrupt
(SVC) (SWI) instruction is executed
FIQ Entered when a high priority (Fast) interrupt is Privileged
raised modes/
IRQ Entered when a low priority (normal) interrupt is Exception
raised modes
Abort Used to handle memory access violations
Undef Used to handle undefined instructions
System Privileged mode using the same registers as User
mode
User Mode under which most applications/OS tasks run Unprivileged
9
PROCESSOR MODES
The processor operates mostly in User Mode and
most applications are executed in this mode.
10
PROCESSOR MODES
Supervisor mode allows the processor to access
protected resources
12
REGISTERS
At any time and in any given mode, the programmer
sees
15 general purpose registers (r0..r14) bank.
1 program counter (PC or r15)
One or two status register
The register banks for the modes are arranged in a
partially overlapping manner.
In user/system modes, one will see a bank of registers
r0..r14, PC, and Current Program Status Register (CPSR)
When the processor switches to, say Abort mode, it will
swap general registers r13 and r14 with different r13 and
r14
In Abort mode, the programmer will also see SPSR_Abort
status register in addition to CPRS
13
REGISTERS
Mode
User/System Supervisor Abort Undefined Interrupt Fast Interrupt
R0 , A1 R0 R0 R0 R0 R0
R1, A2 R1 R1 R1 R1 R1
R2, A3 R2 R2 R2 R2 R2
R3, A4 R3 R3 R3 R3 R3
R4, V1 R4 R4 R4 R4 R4
R5, V2 R5 R5 R5 R5 R5
R6, V3 R6 R6 R6 R6 R6
R7,V4 R7 R7 R7 R7 R7
R8,V5 R8 R8 R8 R8 R8 (FIQ)
R9, V6 R9 R9 R9 R9 R9 (FIQ)
R10,V7 R10 R10 R10 R10 R10 (FIQ)
R11, fp R11 R11 R11 R11 R11 (FIQ)
R12, ip R12 R12 R12 R12 R12 (FIQ)
R13, sp R13 (SVC) R13 (Abort) R13 (Undef) R13 (IRQ) R13 (FIQ)
R14, lr R14 (SVC) R14 (Abort) R14 (Undef) R14 (IRQ) R14 (FIQ)
14
REGISTERS
Program counter is seen by all modes
Mode
User/System Supervisor Abort Undefined Interrupt Fast Interrupt
R15(PC) R15(PC) R15(PC) R15(PC) R15(PC) R15(PC)
17
Program Status Register
The Current Program Status Register (CPSR)
contains condition flags, interrupt enable flags, the
current mode, and state of the processor.
18
Program Status Register
Both CPSR and SPSR have the following format
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
21
THE VECTOR TABLE
For example, when the fast interrupt comes along,
the processor will change the program counter to
0X1C and begin fetching instruction from this
address.
22
THE VECTOR TABLE
The instruction at the location defined by the
exception vector table will usually contain a branch
to the exception handler.
23
THE VECTOR TABLE
By restoring the user registers (a1-a4), PC, and
CPSR, a return to the user program will be achieved.
24
Load-Store Architecture
ARM processor is based on Load-Store Architecture
26
ARM INSTRUCTION SET
32-Bit wide (should be aligned to 4-byte
boundaries in memory)
27
ARM INSTRUCTION SET
General shift (rotate) operation and ALU
operations in a single instruction that executes in a
single cycle
28
INPUT/OUTPUT SYSTEM
Input/output peripherals are handled by the ARM
as memory-mapped devices, with interrupt
support.
29
INPUT/OUTPUT SYSTEM
Input/output peripherals are handled by the ARM
as memory-mapped devices, with interrupt
support.
30
ASSEMBLY PROGRAM EXAMPLE
Consists of ARM instructions, directives, and
comments
stop B stop
32
ASSEMBLY PROGRAM EXAMPLE
After being assembled and converted to machine
code,
0x00000011
MOV r0, #0x11 0x00000000
0x00000000
33
ASSEMBLY PROGRAM EXAMPLE
MOV r0, #0x11
Onto B BUS (
from decode
stage) through a
barrel shifter ( No
shift occurs in this
case) then
through 32-bit
ALU and ALU BUS
to r0
34
ASSEMBLY PROGRAM EXAMPLE
MOV r1, r0, LSL #1
r0 from register
bank onto B BUS
through a barrel
shifter (shift
occurs in this
case, shift by one
position to left)
then through 32-
bit ALU and ALU
BUS to r1
35
ASSEMBLY PROGRAM EXAMPLE
MOV r2, r1, LSL #1
r1 from register
bank onto B BUS
through a barrel
shifter (shift
occurs in this
case, shift by one
position to left)
then through 32-
bit ALU and ALU
BUS to r2
36
ASSEMBLY PROGRAM EXAMPLE
B stop
0xFFFFFE onto B
BUS through a
barrel shifter ( shift
left by 2 positions)
and PC value onto A
BUS then through
32-bit ALU and ALU
BUS to the address
register
Assembler uses
the PC value to
create an address (
that replaces label)
37
ASSEMBLY PROGRAM EXAMPLE
How?
When the instruction (B stop) is executed (at
0x0000000C), the processor will be fetching
instruction at 0x00000014 address, that is the
current value of the PC.
38
ASSEMBLY PROGRAM EXAMPLE
How?
PC( new value) = PC(at the moment) + effective
offset
39
ASSEMBLY PROGRAM EXAMPLE
Factorial calculation (n!)
n! = n(n-1)(1)
Get the value of n
AREA Prog2, CODE, READONLY
ENTRY Copy n to n_factorial
40
END
ASSEMBLY PROGRAM EXAMPLE
Note:
Conditional execution the multiplication
instruction is executed only if subtraction
instruction before it results in zero.
stop B stop
42 END Loop 1
ASSEMBLY PROGRAM EXAMPLE
Shuffle data around swap the contents of two
registers
stop B stop
END
43
ASSEMBLY PROGRAM EXAMPLE
0xF631024C
LDR r0, =0XF631024C 0x00000000
0xF631024C
LDR r1, =0X17539ABD
0x17539ABD
0xE16298F1
EOR r0, r0, r1
0x17539ABD
44
ASSEMBLY PROGRAM EXAMPLE
LDR is normally used to load data from memory to
register.
LDR r0, =0XF631024C
LDR r1, =0X17539ABD
45
ARM Tools
High-level languages are easier to use as they
contain near-English descriptions. Example C, C++
46
ARM Tools
Strictly speaking, the output of the assembler is
object files, which contain debugging and
relocation information, and are used to build a
larger executable file.
47
ARM Tools
With the debugger, one can
access to registers on the chip
view memory
the ability to set and clear breakpoints and watchpoints
views of code in both high-level languages and assembly
48