Question

In: Computer Science

Loop: sll $t1, $s3, 2                         Add $t1, $t1, $s6             &n

Loop: sll $t1, $s3, 2

                        Add $t1, $t1, $s6

                        Lw $t0, 0($t1)

                        Bne $t0, $s5, Exit

                        Addi $s3, $s3, 1

                        j           Loop

How is this MIPS instruction set translated to machine code with the loop starting at 80000 in memory?

Solutions

Expert Solution

- MIPS instruction is byte-addressable, that means that each memory address references an 8-bit Binary Number.

Now, Let's start with the question,

Loop starts at 80000 in memory - Given

All the label needs to be inserted in Symbol Table with their addresses.

Here, Loop and Exit are labeled.

Suppose Loop Takes 8 bits and at one address, we could store one instruction.

Then, 80001 is used for SLL and so on.

Phase 1

Each address is assigned to each instruction and then Loop and Exit would be inserted in Symbol Table with their addresses.

Constant would be converted to their binary equivalent and stored in the assigned address.

OPCODE - MACHINE INSTRUCTION CODE

80000 - Loop

80001 - sll ( Opcode of SLL would be stored in the memory)

80002 - $t1 ( Value of t1 would be stored in the memory)

80003 - $s3 ( Value of s3 would be stored in the memory)

80004 - 2

80005 - Add ( Opcode of ADD would be stored in the memory)

80006 - $t1 ( Value of t1 would be stored in the memory)

80007 - $t1 ( Value of t1 would be stored in the memory)

80008 - $s6 ( Value of s6 would be stored in the memory)

80009 - Lw ( Opcode of LW would be stored in the memory)

80010 - $t0 ( Value of t0 would be stored in the memory)

80011 - 0 + $t1 ( Value of ( 0 + t1) would be stored in the memory)

80012 - Bne ( Opcode of BNE would be stored in the memory)

80013 - $t0 ( Value of t0 would be stored in the memory)

80014 - $s5 ( Value of s5 would be stored in the memory)

80015 - Exit

80016 - Addi ( Opcode of ADDI would be stored in the memory)

80017 - $s3 ( Value of s3 would be stored in the memory)

80018 - $s3 ( Value of s3 would be stored in the memory)

80019 - 1

80019 - j ( Opcode of J would be stored in the memory)

Phase 2

Each instruction would be executed line by line.

Now, it would start at 80000 from Loop, then it goes to SLL - ( SLL, ADD, etc are machine instructions So their code would be fetched from memory and stored in the memory in Phase 1)
Then in Phase 2, Each instruction would be executed accordingly.
For labels, the value would be fetched from the symbol table and then executed. That's how the compiler distinguishes between labels and instructions.

If it's in the symbol table, it's label otherwise it's an instruction.


Related Solutions

Let S = {s1, s2, s3, s4, s5, s6} be the sample space associated with an...
Let S = {s1, s2, s3, s4, s5, s6} be the sample space associated with an experiment having the probability distribution shown in the accompanying table. If A = {s1, s2} and B = {s1, s5, s6}, find the following. Outcome Probability s1 1 3 s2 1 7 s3 1 6 s4 1 6 s5 1 21 s6 1 7 (a) P(A) = P(B) = (b) P(AC) = P(BC) = (c) P(A ∩ B) = (d) P(A ∪ B) =...
Consider the three transactions T1, T2, and T3, and the schedules S5 and S6 given below....
Consider the three transactions T1, T2, and T3, and the schedules S5 and S6 given below. Show all conflicts and draw the serializability (precedence) graphs for S5 and S6, and state whether each schedule is serializable or not. If a schedule is serializable, write down the equivalent serial schedule(s). T1: r1(x); r1(z); w1(x); T2: r2(z); r2(y); w2(z); w2(y); T3: r3(x); r3(y); w3(y); S5: r1(X); r2(Z); r1(Z); r3(X); r3(Y); w1(X); c1; w3(Y); c3; r2(Y); w2(Z); w2(Y); c2; S6: r1(X); r2(Z); r1(Z);...
The following is the original code, (add, t1, 3, 5) (assign, a, t1) (add, t2, 3,...
The following is the original code, (add, t1, 3, 5) (assign, a, t1) (add, t2, 3, 5) (sub, t3, t2, z) (assign, b, t3) Constant folding is applied to give the following, (assign, t1, 8) (assign, a, t1) (assign, t2, 8) (sub, t3, t2, z) (assign, b, t3) After the constant folding is applied, the (assign, t2, 8) becomes redundant. What optimizations should take place in order to remove this redundancy in the constant folded code? Also show the optimized...
Find the data hazards in the following code segment lw $t1,0($t1) addi $t1,$t1,100 or $t2,$t3,$t1 add...
Find the data hazards in the following code segment lw $t1,0($t1) addi $t1,$t1,100 or $t2,$t3,$t1 add $a0,$a1,$t2 ori $a0,$a0,42 add $t5,$a0,$t2 Reorder the following code segment to remove the data hazards. Assume that data forwarding takes place: lw $t0,24($a0) sub $t4,$t4,$t0 sub $t8,$t8,$t3 add $t6,$t6,$t5 mul $t7,$t7,$t1 What is the CPI for the reordered sequence of instructions in the preceding problem?
Open Average Test Scores while loop, comment out the while loop and add a for loop...
Open Average Test Scores while loop, comment out the while loop and add a for loop that averages 4 test scores. Code C# While loop code using System; class Program { static void Main() { int count = 0, total = 0, number;    while (count < 3) { Console.Write("Enter a number: "); number = Convert.ToInt32(Console.ReadLine()); total += number; count++; }    double average = total / 3.0; Console.Write("Average = " + average.ToString("####0.00")); } }
R= Ro(1/2)n n= number of half lifetimes= t/t1/2 (a)n= 2/2= 1 R= Ro(1/2)n R=3000(1/2)1 R= 1500...
R= Ro(1/2)n n= number of half lifetimes= t/t1/2 (a)n= 2/2= 1 R= Ro(1/2)n R=3000(1/2)1 R= 1500 counts/sec (b)n= 6/2= 3 R= Ro(1/2)n R=3000(1/2)3 R= 375 counts/sec (c) n= 10/2= 5 R= Ro(1/2)n R=3000(1/2)5 R= 93.75 counts/sec (d) n= 20/2= 10 R= Ro(1/2)n R=3000(1/2)10 R= 2.93 counts/sec What is the mean life of this nucleus? f. Suppose that the Geiger counter detects 10% of all the radioactive decays. What is the total number of radioactive nuclei at time t = 0?...
Which codes add 1 to integer n? 1) n=n+1; 2) n++; 3)++n; 4) n+=1; 5) n=--n+2
Which codes add 1 to integer n? 1) n=n+1; 2) n++; 3)++n; 4) n+=1; 5) n=--n+2
1.write a small program using a loop to add a series of numbers 2.write a function...
1.write a small program using a loop to add a series of numbers 2.write a function called "main" that performs several given steps. Be sure to call the main() function so that its code executes In python and doesn't have to be long. just long enough to do what it says. Thank you.
How many elements of order 2 are there in S5 and in S6? How many elements...
How many elements of order 2 are there in S5 and in S6? How many elements of order 2 are there in Sn? (abstract algebra)
Convert in machine code for MIPS LW S5, 33(S2); Add R1, T3, S5; Sub T4, S3,...
Convert in machine code for MIPS LW S5, 33(S2); Add R1, T3, S5; Sub T4, S3, R3; SW T4, 124(T7);
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT