0% found this document useful (0 votes)
178 views

COD Homework2

This document contains 10 questions about computer organization and design concepts related to MIPS assembly code and machine language. Question 1 asks to translate a C statement to MIPS assembly code. Question 2 asks to translate MIPS assembly code to a C statement. Question 3 asks to rewrite the MIPS assembly code from question 2 to minimize instructions.

Uploaded by

Sang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
178 views

COD Homework2

This document contains 10 questions about computer organization and design concepts related to MIPS assembly code and machine language. Question 1 asks to translate a C statement to MIPS assembly code. Question 2 asks to translate MIPS assembly code to a C statement. Question 3 asks to rewrite the MIPS assembly code from question 2 to minimize instructions.

Uploaded by

Sang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Computer Organization and Design

Homework 2
1) For the following C statement, what is the corresponding MIPS assembly
code? Assume that the variables i and j are assigned to registers $s0 and $s1,
respectively. Assume that the base address of the arrays A and B are in
registers $s6 and $s7, respectively.
B[8] = A[i-j];
2) For the following MIPS assembly instructions, what is the corresponding C
statement? Assume that the variables f and g are assigned to registers $s0 and
$s1, respectively. Assume that the base address of the arrays A and B are in
registers $s6 and $s7, respectively.
sll $t0, $s0, 2
add $t0, $s6, $t0
sll $t1, $s1, 2
add $t1, $s7, $t1
lw $s0, 0($t0)
addi $t2, $t0, 4
lw $t0, 0($t2)
add $t0, $t0, $s0
sw $t0, 0($t1)

# $t0 = f * 4
# $t0 = &A[f]
# $t1 = g * 4
# $t1 = &B[g]
# f = A[f]

3) For the MIPS assembly instructions in Exercise 2, rewrite the assembly code
to minimize the number if MIPS instructions (if possible) needed to carry out
the same function.
4) Translate the following MIPS code to machine language:
addi $t0, $s6, 4
add $t1, $s6, $0
sw $t1, 0($t0)
lw $t0, 0($t0)
add $s0, $t1, $t0
5) Translate the following C code to MIPS assembly code. Use a minimum
number of instructions. Assume that the values of a, b, i, and j are in
registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds
the base address of the array D.
for(i=0; i<a; i++)
for(j=0; j<b; j++)
D[4*j] = i + j;

6) Convert the following machine code program to assembly for MIPS


00011010010000000000000000000011
00100000000000000000000000000000
10101110001010110000000000000000
10101110001010100000000000000010
00100001001010010000000000001000
7) Pseudo-instructions are not part of the MIPS instruction set but often appear
in MIPS programs. The assembler then has to convert them into a small set of
real MIPS instructions. For each of the following pseudo-instructions, convert
them to a very short equivalent sequence of real MIPS instructions. If you
need a temporary register, you should use $at.

Note that small is a constant that fits in 16 bits (i.e. small enough for the
immediate field of an instruction), and big is a constant that is 32 bits (i.e.
too long for the immediate field).
8) Assume that we would like to expand the MIPS register file to 128 registers
and expand the instruction set to contain four times as many instructions.
a. How this would this affect the size of each of the bit fields in the R-type
instructions?
b. How this would this affect the size of each of the bit fields in
the I-type instructions?
9) Find the shortest sequence of MIPS instructions that extracts bits 16 down to
11 from register $t0 and uses the value of this field to replace bits 31 down to
26 in register $t1 without changing the other 26 bits of register $t1.
10) Show how the value 0xabcdef12 would be arranged in memory of a
little-endian and a big-endian machine. Assume the data is stored starting at
address 0.
The end

You might also like