MES Not Fail-Act 1
MES Not Fail-Act 1
-------------------------------------------------------------------------------------------------------------------
2. Explain the Architecture of an ARM Embedded device with the help of a neat
diagram.
• The CPSR is divided into four fields, each 8 bits wide: flags, status,
extension, and control.
• The extension and status fields are reserved for future use,
while the control field contains the processor mode, state, and interrupt
mask bits, and
the flags field contains the condition flags
(N-negative, Z-zero, C-carry, V-overflow).
Some ARM processor cores have extra bits allocated. Ex: the J bit, which can be
found in the flags field, is only available on Jazelle-enabled processors, which
execute 8-bit instructions.
-------------------------------------------------------------------------------------------------------------------
4. With a neat diagram Explain System Hardware.
(Same as Question 2)
-------------------------------------------------------------------------------------------------------------------
5. What are Core Extensions? Explain in detail all the three extensions for ARM
Core.
(I doubt all three will come in full detail. If they do. Write only few lines for each one)
*Core extensions speed up and organize main memory as well as extend the
instruction set, they are standard components placed next to the ARM core.
They improve performance, manage resources, and provide extra functionality and
are designed to provide flexibility in handling particular applications.
*There are three hardware extensions ARM wraps around the core:-
I) Cache and Tightly coupled memory:-
*The cache is a block of fast memory placed between main memory and the core.
*It allows for more efficient fetches from some memory types.
*With a cache, the processor core can run for the majority of the time without
having to wait for data from slow external memory.
A cache provides an overall increase in performance but at the expense of
predictable
execution.
But for real-time systems it is paramount that code execution is deterministic—
the time taken for loading and storing instructions or data must be predictable.
*This is achieved using a form of memory called tightly coupled memory (TCM).
TCM is fast SRAM located close to the core and guarantees the clock cycles
required to fetch instructions or data—critical for real-time algorithms requiring
deterministic behavior.
*TCMs appear as memory in the address map and can be accessed as fast
memory.
*By combining both technologies, ARM processors can have both improved
performance and predictable real-time response.
-------------------------------------------------------------------------------------------------------------------
*The entries in the vector table are instructions that branch to specific
routines designed to handle that particular exception or interrupt.
*Each entry contains a form of branch instruction pointing to the start of a specific
routine:-
-Reset vector (RESET): The location of the first instruction executed by the
processor when power is applied. This instruction branches to the initialization
code.
-Prefetch abort vector (PABT): It occurs when the processor attempts to fetch an
instruction from an address without the correct access permissions.
-Data abort vector (DABT): It occurs when an instruction attempts to access data
memory without the correct access permissions.
-Fast interrupt request vector (FIQ): It is similar to the interrupt request but is
reserved for hardware requiring faster response times. It can only be raised if
FIQs are not masked in the cpsr.
-------------------------------------------------------------------------------------------------------------------
7. Explain the 5-stage pipelining used in ARM. Which ARM core implements 5-
stage pipelining.
• A pipeline is a mechanism RISC processors use to execute instructions.
• Using a pipeline speeds up execution by fetching the next instruction
while other instructions are being decoded and executed.
• The ARM9 core implements 5-stage pipelining.
*As the pipeline length increases, the amount of work done at each stage is reduced, which
allows the processor to attain a higher operating frequency.
This in turn increases the performance.
*This also increases system latency
(OPTIONAL)
-------------------------------------------------------------------------------------------------------------------
8. What are the various processor modes in ARM? Detail each one.
(Repeated in 13.)
The first 5 bits of the cpsr are signified as mode selection bits.
The processor mode determines which registers are active and the access rights to
the cpsr register itself.
*There are seven processor modes in total: six privileged modes (abort, fast
interrupt request, interrupt request, supervisor, system, and undefined) and one
non privileged mode (user):-
Abort: The processor enters abort mode when there is a failed attempt to access
memory.
Fast interrupt request and interrupt request: These modes correspond to the
two interrupt levels available on the ARM processor.
Supervisor: Supervisor mode is the mode that the processor is in after reset and
is generally the mode that an operating system kernel operates in.
System: System mode is a special version of user mode that allows full read-write
access to the cpsr.
-------------------------------------------------------------------------------------------------------------------
*When the processor is in the interrupt request mode, the user registers r13 and
r14 are banked.
The user registers are replaced with registers r13_irq and r14_irq,
respectively.
-------------------------------------------------------------------------------------------------------------------
Abort: The processor enters abort mode when there is a failed attempt to access
memory.
-Replaces registers r13 and r14
Fast interrupt request and interrupt request: These modes correspond to the
two interrupt levels available on the ARM processor.
-Fast interrupt request Replaces registers r8 to r14
-Interrupt request only replaces registers r13 to r14
Supervisor: Supervisor mode is the mode that the processor is in after reset and
is generally the mode that an operating system kernel operates in.
-Replaces registers r13 and r14
System: System mode is a special version of user mode that allows full read-write
access to the cpsr.
-Aswell as access to the spsr
-------------------------------------------------------------------------------------------------------------------
11. Differentiate between ARM state and Thumb State in ARM Processor technology.
The state of the core determines which instruction set is being executed. There are three instruction
sets: ARM, Thumb, and Jazelle.
*ARM State:-
-When both J and T bits are 0 in the cpsr, the processor is in ARM state and executes 32-bit ARM
instructions.
*Thumb State:-
-When the T bit is 1, then the processor is in Thumb state.
To change states the core executes a specialized branch instruction
-Once in Thumb state the processor is executing purely Thumb 16-bit instructions.
*Jazelle State:-
-The ARM designers introduced a third instruction-set called Jazelle.
Jazelle executes 8-bit instructions and is a hybrid mix of software and hardware designed to speed up
the execution of Java bytecodes.
-It is important to note that the hardware portion of Jazelle only supports a subset of the Java
bytecodes; the rest are emulated in software.
(I think sir only wanted this Table, but Im too lazy :0 to remove the top part )
-------------------------------------------------------------------------------------------------------------------
12. What are the various condition flags available in ARM processors? Detail each
flag.
*Condition flags are updated by comparisons and the result of ALU operations
that specify the S instruction suffix.
*With processor cores that include the DSP extensions, the Q bit indicates if an overflow or
saturation has occurred in an enhanced DSP instruction.
*The flag is “sticky” in the sense that the hardware only sets this flag.`
*To clear the flag you need to write to the cpsr directly.
-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
14. Explain the use of Barrel Shifters in ARM Processor with suitable examples?
The wide range of second operand shifts available on arithmetic and logical instructions is a
very powerful feature of the ARM instruction set.
We can illustrate this with an example of the use of the inline barrel shifter
Register r1 is first shifted one location to the left to give the value of twice r1.
The ADD instruction then adds the result of the barrel shift operation to register r1.
The final result transferred into register r0 is equal to three times the value stored in register r1.
PRE
r0 = 0x00000000
r1 = 0x00000005
ADD r0, r1, r1, LSL #1
POST
r0 = 0x0000000f
r1 = 0x00000005
We can see that Multiplication can be done, by a Shift and an ADD instruction. Which takes
advantage of the inline barrel shifter to complete the operation in a Single Cycle.
This is more resource efficient than using the expensive MUL operation.
-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
16. Explain single register Load-Store addressing mode syntax, table, index mode with an
example.
Load-store instructions transfer data between memory and processor registers
Single Register Load-Store 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.
Syntax:
<LDR|STR>{<cond>}{B} Rd,addressing1
LDR{<cond>}SB|H|SH Rd, addressing2
STR{<cond>}H Rd, addressing2
The ARM instruction set provides different modes for addressing memory.
These modes incorporate one of the indexing methods:
i) Preindex with writeback: calculates an address from a base register plus address offset and
then updates that address base register with the new address.
Useful for traversing a stack/array
ii) Preindex: The preindex offset is the same as the preindex with writeback but does not update
the base register.
Useful for ACCESSING an element in a datastructure
iii) Postindex: Only updates the base register after the address is used.
Useful for traversing an array
-------------------------------------------------------------------------------------------------------------------
17. Explain the different Logical Instructions in ARM Processor with an example.
Logical instructions perform bitwise logical operations on the two source registers.
Syntax: <instruction>{<cond>}{S} Rd, Rn, N
-------------------------------------------------------------------------------------------------------------------
18. Write an ALP to find the sum of the first 10 integer numbers.
AREA SUM10, CODE, READONLY
EXPORT __main
__main
ENTRY
MOV R1, #0
BNE LOOP
STOP B STOP
END
Output:-
R0 ← 0x00000000
R1 ← 0x00000037
R3 ← 0x40000000
Memory-
Address: 0x40000000
37 00 00 00
-------------------------------------------------------------------------------------------------------------------
19. Write an ALP to find the smallest number from an array of ten 32-bit numbers.
R1 ← 0x00000048
R2 ← 0x22222222
R4 ← 0x77777777
R5 ← 0x00000000
R9 ← 0x40000000
Memory-
Address: 0x40000000
22 22 22 22
-------------------------------------------------------------------------------------------------------------------
20. Briefly explain what happens when an IRQ and FIQ exception is raised with an ARM
processor.
-The processor mode is changed by a program by hardware when the core responds to an
exception or interrupt
-Exceptions and interrupts suspend the normal execution of sequential instructions and jump to
a specific location.
-The figure shows the core changing from user mode to interrupt request mode, which happens
when an interrupt request occurs due to an external device raising an interrupt to the
processor core.
-This change causes user registers r13 and r14 to be banked. The user registers are replaced
with registers r13_irq and r14_irq, respectively.
-Figure also shows a new register appearing in interrupt request mode:
the saved program status register (spsr), which stores the previous mode’s cpsr.
You can see in the diagram the cpsr being copied into spsr_irq.
-Note that the spsr can only be modified and read in a privileged mode.
There is no spsr available in user mode.
-After the exception is handled, a special return instruction is used that instructs the core to
restore the original cpsr from the spsr_irq and bank-in the user registers r13 and r14.
-------------------------------------------------------------------------------------------------------------------
Code Optimization
-Embedded software projects often contain a few key subroutines that dominate system
performance. By optimizing these routines you can reduce the system power consumption and
reduce the clock speed needed for real-time operation.
-Code Optimization can turn an infeasible system into a feasible one, or an uncompetitive
system into a competitive one.
Profiliing
-The first stage of any optimization process is to identify the critical routines and measure their
current performance.
A Profiler is a tool that measures the proportion of time or processing cycles spent in each
subroutine. You use a profiler to identify the most critical routines
Cycle Counting
- A Cycle counter measures the number of cycles taken by a specific routine.
You can measure your success by using a cycle counter to benchmark a given subroutine before
and after an optimization.
ARM implementations do not normally contain cycle-counting hardware, so to easily measure
cycle counts you should use an ARM debugger with ARM simulator.
-------------------------------------------------------------------------------------------------------------------
-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, which allows an operating system
routine to be called in a privileged mode.
-Each SWI instruction has an associated SWI number, which is used to represent a particular
function call or feature.
-------------------------------------------------------------------------------------------------------------------
23. Assuming suitable data explain the SWI handler implementation.
Code called the SWI handler is required to process the SWI call.
The code fragment determines what SWI number is being called and places that number into
register r10.
You can see from this example that the load instruction first copies the complete SWI
instruction into register r10.
The BIC instruction masks off the top bits of the instruction, leaving the SWI number. We
assume the SWI has been called from ARM state.
-------------------------------------------------------------------------------------------------------------------
24. Explain CMN, CMP, TEQ, TST instructions with suitable examples.
-The comparison instructions are used to compare or test a register with a 32-bit value.
They update the cpsr flag bits according to the result, but do not affect other registers.
-After the bits have been set, the information can then be used to change program flow by using
conditional execution
-You do not need to apply the S suffix for comparison instructions to update the flags
Syntax: <instruction>{<cond>} Rn, N
-------------------------------------------------------------------------------------------------------------------
25. What are the different types of Unconditional Branch Instructions? Detail each one.
-A branch instruction changes the flow of execution or is used to call a routine.
This type of instruction allows programs to have subroutines.
-The change of execution flow forces the program counter pc to point to a new address.
The ARM instruction set includes four different branch instructions.
*Syntax:
B{<cond>} label
BL{<cond>} label
BX{<cond>} Rm
BLX{<cond>} label | Rm
-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.
-T refers to the Thumb bit in the cpsr. When instructions set T, the ARM switches to Thumb state
-------------------------------------------------------------------------------------------------------------------
26. Explain the following instructions: a) LDR Rd, =constant b) ADR Rd, Label
*LDR Rd, =constant : Writes a 32-bit constant to a register using whatever instructions are
available. It defaults to a memory read if the constant cannot be encoded using other
instructions.
Example:
LDR r0, =0x12345678 ; Load 0x12345678 into r0
LDR r1, =0x100 ; Load 0x100 into r1
*ADR Rd, label: Writes a relative address into a register, which will be encoded using a pc-
relative expression.
Example:
ADR r2, my_label ; Load the address of 'my_label' into r2
.
.
my_label:
DCD 0xDEADBEEF ; Some data at this address
-------------------------------------------------------------------------------------------------------------------
tmp = mem32[Rn]
mem32[Rn] = Rm
Rd = tmp
-------------------------------------------------------------------------------------------------------------------