Question: Consider the following loop: S: = 0; for K: = 1 to 100 do S: = S - K; A straightforward translation of this into
S: = 0;
for K: = 1 to 100 do
S: = S - K;
A straightforward translation of this into a generic assembly language would look something like this:
.png)
A compiler for a RISC machine will introduce delay slots into this code so that the processor can employ the delayed branch mechanism. The JMP instruction is easy to deal with, because this instruction is always followed by the SUB instruction; therefore, we can simply place a copy of the SUB instruction in the delay slot after the JMP. The BEQ presents a difficulty. We can't leave the code as is, because the ADD instruction would then be executed one too many times. Therefore, a NOP instruction is needed. Show the resulting code.
LD LD SUB BEQ ADD JMP R1,0 R2.1 R1, R1, R2 R2, 100, EXIT R2, R2,1 LP keep value of S in R1 keep value of in R2 LP done if K = 100 else increment K back to start of loop
Step by Step Solution
3.51 Rating (168 Votes )
There are 3 Steps involved in it
LD LD LP SUB LP1 BEQ NOP ADD JMP SUB R10 R21 ... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
896-C-S-S-A-D (2588).docx
120 KBs Word File
