retagged by
712 views
0 votes
0 votes

How will the compiler reorder the below statements so that it doesn't have any stall cycle ?

Load R2, N // Load the size of the list.  
Clear R3 //Initialize sum to 0  
Move R4, #NUM1‬ // Get address of the first number. 
LOOP: Load R5, (R4)// Get the next number.  
Add R3, R3, R5 // Add this numberto sum.   
Add R4, R4, #4 //Increment the pointer to the list.   
Subtract R2, R2, #1 // Decrement the counter.   
Branch_if [R2]>0 LOOP //Branch back if notfinished.   
Store R3, SUM //Store thefinal sum.
retagged by

2 Answers

0 votes
0 votes
Load R2, N // Load the size of the list.
Clear R3 //Initialize sum to 0
Move R4, #NUM1‬ // Get address of the first number
.  LOOP: Load R5, (R4)// Get the next number.
Add R3, R3, R5 // Add this numberto sum.
Add R4, R4, #4 //Increment the pointer to the list.
Branch_if [R2]>0 LOOP //Branch back if notfinished.   
Subtract R2, R2, #1 // Decrement the counter.
Store R3, SUM //Store thefinal sum.

can we shift the sub instruction down to branch so that store will not be fetched since ID stage of Branch and If of sub will overlap 

and in ID satge Branch change the pc value and will transfer the control to loop if true .

0 votes
0 votes
Load R2, N // Load the size of the list.  
Clear R3 //Initialize sum to 0  
Move R4, #NUM1‬ // Get address of the first number. 
LOOP: (R4)// Get the next number.  
Add R3, R3, R5 // Add this numberto sum.   
Add R4, R4, #4 //Increment the pointer to the list.   
Subtract R2, R2, #1 // Decrement the counter.   
Branch_if [R2]>0 LOOP //Branch back if notfinished.   
Load R5, (R4)
Store R3, SUM //Store thefinal sum.

Related questions

2 votes
2 votes
2 answers
1
radha gogia asked Jan 24, 2016
745 views
If I have numbers from {1,2,...7} then in how many ways can I form an AVL tree without any rotation required ?How to approach this question ?
0 votes
0 votes
3 answers
2
Lohithendra Kumar asked Jun 10, 2016
408 views
i think that these statements have become _____ to him, it won't have any impact as he been hearing them since he was a kid.a.interestingb.humorousc.platituded.vigorous