Assignment 2
Assignment 2
Computer Architecture
Chapter 2
Instruction Set Architecture
Due Date: 2-05-2019
Question # 1 (C to MIPS)
C to MIPS. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3,
and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and
$s7, respectively.
f = g + A[B[4]-B[3]];
For the C statement above, what is the corresponding MIPS assembly code?
Question # 2
while( A[i]== B[i])
i=i+1;
Convert the above C code to MIPS assembly. Base address of A and B are in $s0 and $s1
respectively and variable “i” is assigned to $s2.
Question # 3
For the following C statement, what is the corresponding MIPS assembly code? Assume that the
variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume
that the base address of the arrays A and B are in registers $s6 and $s7, respectively.
B[8] = A[i−j];
Question #4
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;
Question # 5
Translate the following C code to MIPS assembly code. Use a minimum number of instructions.
Assume that the values of num1,num2 and result are in registers $a0, $a1, and $v0, a respectively
Question # 6 (MIPS to C)
MIPS to C. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3,
and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and
$s7, respectively. Convert the following program into C.
MIPS Code:
Question # 7
Translate the following MIPS code to C. Assume that the variables f, g, h, i, and j are assigned to
registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A
and B are in registers $s6 and $s7, respectively. MIPS Code:
Question # 10
1. Provide the type and assembly language instruction for the following binary value:
0000 0010 0001 0000 1000 0000 0010 0000two
2. Provide the type and hexadecimal representation of following instruction: sw $t1, 32($t2)
3. Provide the type, assembly language instruction, and binary representation of instruction
described by the following MIPS fields:
op=0, rs=3, rt=2, rd=3, shamt=0, funct=34
4. Provide the type, assembly language instruction, and binary representation of instruction
described by the following MIPS fields:
op=0x23, rs=1, rt=2, const=0x4
5. 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.