See next code MOV R0 0 START LDR R2 R1 4 ADD R3 R2 R2 ADD R0
See next code
MOV R0, #0
START: LDR R2, [R1], #4
ADD R3, R2, R2
ADD R0, R0, #1
CMP R0, #12
BNE START
A- How many cycles the next loop needs for execution?
B- Use pre-loading to reduce the cycle count and specify the new cycle per loop and write the new code?
C- Use loop unrolling 4 times to reduce cycles per loop. Specify the new cycle and write the new code?
Solution
Answer A
Instruction
Meaning
Cycles
MOV R0, #0
Clear accumulator or initialization
1
START: LDR R2, [R1], #4
Load next word into R2
2
ADD R3, R2, R2
R3= R2+R2
1
ADD R0, R0, #1
Increment R0 by 1
1
CMP R0, #12
R0-12
1
BNE START
Branch if not equal
2
this loop will run for 12 times and each loop instruction swould require 7 cycles
| Instruction | Meaning | Cycles |
| MOV R0, #0 | Clear accumulator or initialization | 1 |
| START: LDR R2, [R1], #4 | Load next word into R2 | 2 |
| ADD R3, R2, R2 | R3= R2+R2 | 1 |
| ADD R0, R0, #1 | Increment R0 by 1 | 1 |
| CMP R0, #12 | R0-12 | 1 |
| BNE START | Branch if not equal | 2 |
![See next code MOV R0, #0 START: LDR R2, [R1], #4 ADD R3, R2, R2 ADD R0, R0, #1 CMP R0, #12 BNE START A- How many cycles the next loop needs for execution? B- Us See next code MOV R0, #0 START: LDR R2, [R1], #4 ADD R3, R2, R2 ADD R0, R0, #1 CMP R0, #12 BNE START A- How many cycles the next loop needs for execution? B- Us](/WebImages/7/see-next-code-mov-r0-0-start-ldr-r2-r1-4-add-r3-r2-r2-add-r0-993041-1761510858-0.webp)
![See next code MOV R0, #0 START: LDR R2, [R1], #4 ADD R3, R2, R2 ADD R0, R0, #1 CMP R0, #12 BNE START A- How many cycles the next loop needs for execution? B- Us See next code MOV R0, #0 START: LDR R2, [R1], #4 ADD R3, R2, R2 ADD R0, R0, #1 CMP R0, #12 BNE START A- How many cycles the next loop needs for execution? B- Us](/WebImages/7/see-next-code-mov-r0-0-start-ldr-r2-r1-4-add-r3-r2-r2-add-r0-993041-1761510858-1.webp)