Consider the following loop: S: = 0; for K: = 1 to 100 do S: = S

Question:

Consider the following loop:
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:
Consider the following loop:
S: = 0;
for K: = 1 to

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.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: