ARM Microcontroller - CIE 2
ARM Microcontroller - CIE 2
Microcontroller
Vanitha A
Assistant Professor
ARM Organization and Implementation
In this instruction sequence, all parts of the processor are active in every cycle.
The simplest way to view breaks in the ARM pipeline is to observe that:
• All instructions occupy the datapath for one or more adjacent cycles.
• For each cycle that an instruction occupies the datapath, it occupies the
decode logic in the immediately preceding cycle.
• During the first datapath cycle each instruction issues a fetch for the next
instruction but one.
• Branch instructions flush and refill the instruction pipeline.
• ARM instruction execution
• Data processing instructions
• A data processing instruction requires two operands.
• one operand is always a register and the other is either a
second register or an immediate value.
• The second operand is passed through the barrel shifter for
general shift operation, then it is combined with the first
operand in the ALU using a general ALU operation.
• The result from the ALU is written back into the destination
register.
• All these operations take place in a single clock cycle.
Eg: ADD R0,R1,R2
ADD R0,R1, #05h
• Data transfer instructions
• A data transfer (load or store) instructions, A register is used
as the base address, which is added (or subtracted) an offset
(register or an immediate value).
• In first cycle address is sent to the address register, and in a
second cycle the data transfer takes place.
• During the data transfer cycle, the ALU holds the address
components from the first cycle and compute an auto-
indexing modification to the base register if this is required.
• the incremented PC value is stored in the register bank at the
end of the first cycle and address register is free to accept the
data transfer address for the second cycle.
• At the end of the second cycle the PC is fed back to the
address register to allow instruction prefetching to continue.
• The data path operation for the two cycles of a data store
instruction (SIR) with an immediate offset are shown below:
• When the instruction specifies the store of a byte data type,
the 'data out' block extracts the bottom byte from the register
and replicates it four times across the 32-bit data bus.
• Load instructions follow a similar pattern except that the data
from memory only gets as far as the 'data in' register on the
second cycle .
• A third cycle is needed to transfer the data from there to the
destination register.
Note
• The address register is a pipeline register between the
processor data path and the external memory.
• The address register can produce the memory address for the
next cycle a little before the end of the current cycle.
Branching Instructions
• Branch instructions compute the target address in the first
cycle as shown in Figure
• Branch instructions compute the target address in the first
cycle .
• A 24-bit immediate field is extracted from the instruction and
then shifted left two bit positions to give a word-aligned
offset which is added to the PC.
• The result is issued as an instruction fetch address, and while
the instruction pipeline refills the return address is copied
into the link register (r14) if required (cycle 2).
• The third cycle, which is required to complete the pipeline
refilling and also used to make a small correction to the
value stored in the link register in order to point directly at
the instruction which follows the branch.
ARM implementation
• Clocking scheme
• Datapath timing
• Adder design
• ALU functions
• The barrel shifter
• Multiplier design
• The register bank
• Datapath layout
• Control structures
• Datapath timing
• The normal timing of the datapath components in a 3-stage
pipeline is illustrated in Figure
ARM
Back: CMP R0,#0
BEQ exit
.
Loop
.
B back
Exit:
.
• Do while loop ARM
do Start:
{ :
Loop Loop
} :
While(expression) CMP R0,#0
: BNE start
Exit:
:
Stop: B Stop
end
Functions and procedures
• Program design
• Large programs are broken down into components that are
small for testing instead of a large monolithic program that is
too complex to test fully and hidden 'bugs’ .
• Each small software component should perform a specified
operation using a well-defined interface.
• The full program should be designed as a hierarchy of
components.
• The top of the hierarchy is the program called main.
• At the lowest level of the hierarchy there are leaf routines;
these are routines which do not themselves call any lower-
level routines.
• The bottom-level routines will be library or system functions
All the stack space is recovered on function exit and reused for
subsequent calls,
Data alignment
• The ARM C compiler generally aligns data items on
appropriate boundaries:
• Bytes are stored at any byte address.
• Half-words are stored at even byte addresses.
• Words are stored on four-byte boundaries.
• The data items of different types are declared at the same
time, the compiler will introduce padding for alignment.
Eg: struct SI {char c; int x; short s;}
• This structure will occupy three words of memory as shown
in Figure
/* Hello World in C */
#include int main()
{
printf( "Hello World\n" );
return ( 0 );
}
Show how the following data is organized in memory:
struct SI
{
char c;
int x;
};
struct S2
{
char c2[5];
SI si [2];
}