Question 2.5.3: Translating MIPS Assembly Language into Machine Language We ......

Translating MIPS Assembly Language into Machine Language
We can now take an example all the way from what the programmer writes to what the computer executes. If $ t1 has the base of the array A and $ s2 corresponds to h, the assignment statement

A[300] = h + A[300];

is compiled into

lw $ t0, 1200($t1)   # Temporary reg $ t0 gets A[300]
add $ t0, $s2,$t0    # Temporary reg $ t0 gets h + A[300]
sw $ t0, 1200($t1)   # Stores h + A[300] back into A[300]

What is the MIPS machine language code for these three instructions?

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.

For convenience, let’s first represent the machine language instructions using decimal numbers. From Figure 2.5, we can determine the three machine language instructions:

The 1w instruction is identified by 35 (see Figure 2.5) in the first field (op). The base register 9 ($ t1) is specified in the second field (rs), and the destination register 8 ($ t0) is specifi ed in the third field (rt). The offset to select A[300] (1200 = 300 × 4) is found in the final field (address).
The add instruction that follows is specified with 0 in the first fild (op) and 32 in the last field (funct). The three register operands (18, 8, and 8) are found in the second, third, and fourth fields and correspond to $ s2, $t0, and $ t0.
The sw instruction is identified with 43 in the first field. The rest of this final instruction is identical to the 1w instruction.

Since1200_{\mathrm{ten}}=0000\,0100\,1011\,0000_{\mathrm{two}} form is:

Note the similarity of the binary representations of the first and last instructions. The only difference is in the third bit from the left, which is highlighted here.

 

Op

 

rs

 

rt

 

rd

address/ shamt  

funct

35 9 8 1200
0 18 8 8 0 32
43 9 8 1200

 

100011 01001 01000 0000 0100 1011 0000
000000 10010 01000 01000 00000 100000
101011 01001 01000 0000 0100 1011 0000
2.5

Related Answered Questions

Question: 2.10.4

Verified Answer:

The first step in converting hexadecimal to binary...