Professional Documents
Culture Documents
Computer Architecture and Organization Worksheet-1: Taye G. (Asst. Professor)
Computer Architecture and Organization Worksheet-1: Taye G. (Asst. Professor)
Worksheet-1
1. Use a minimal number of MIPS assembly instructions and identify all possible
addressing modes.
a) g = 4*h + 8-h;
b) while (h== 5)
g = 2*h + 8-h;
g = 8*h+ (8-h)
1. Use a minimal number of MIPS assembly instructions and identify all possible
addressing modes.
a) f = 2*g*h+ (h − 5);
b) while (i== 5
f = = 2*g*h + (h − 5);
f = 4*h – (h+8)
2. Use a minimal number of MIPS assembly instructions and identify all possible
addressing modes.
a) for (i=1;i<=4;i++)
{
for (j=1; j<=4;j++)
{
g = 2*h + 8-h;
}
}
3. Use a minimal number of MIPS assembly instructions and identify all possible
addressing modes.
b) for (i=1;i<=4;i++)
{
for (j=1; j<=4;j++)
{
f = = 2*g*h + (h − 5);
}
}
B[8] = A[i−j];
5. 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.
6. Assume that registers $s0 and $s1 hold the values 0x80000000 and
0xD0000000, respectively.
a) What is the value of $t0 for the following assembly code?
b) For the contents of registers $s0 and $s1 as specified above, what is
c) For the contents of registers $s0 and $s1 as specified above, what is
the value of $t0 for the following assembly code?
A = C[0] << 4;
9. Assume $t0 holds the value 0x00101000. What is the value of $t2 after the
following instructions?
a) Assume that the register $t1 is initialized to the value 10. What is the
value in register $s2 assuming $s2 is initially zero?
b) For each of the loops above, write the equivalent C code routine.
Assume that the registers $s1, $s2, $t1, and $t2 are integers A, B, i,
and temp, respectively.
c) For the loops written in MIPS assembly above, assume that the
register $t1 is initialized to the value N. How many MIPS instructions
are executed?
a) Assume that the register $t1 is initialized to the value 10. What is the
value in register $s2 assuming $s2 is initially zero?
a) Assume that the register $t1 is initialized to the value 10. What is the
value in register $s2 assuming $s2 is initially zero?
13. Translate the following Java statement into MIPS assembly code. Assume that
x, y, z, q are stored in registers $s1-$s4. You may use the other registers to hold
intermediate results.
x = x + y + z - q;
14. How would you implement in assembly a shift-left- logical (SLL) pseudo-
instruction for a machine that didn’t have this particular instruction? Be sure your
SLL instruction can shift up to W bits where W is the machine word size in bits.
Assume the pseudo-instruction you’re implementing for this particular answer is
SLL $s0,$s1,23
$S1 12 12 16
$S2 16 16 20
$S3 20 20 24
$S4 24 24 28
a) Give the values of registers $1, $2, and $3 after this instruction is
executed:
lw $3, 12($1)
for i = 0 to 39
A[i] = 2 * i – A[i];
MIPS Code:
addi $s1, $zero, -1
lw $t3, 0($s4)
sw $t4, 0($s4)
j Loop
Exit:
18. Consider the following C++ code and write the equivalent MIPS code.
i = 0;
while (i < 47)
{
A[i] = i + 33;
i++;
}
li $t1,7
li $t2,3
sub $t3,$t1,$t2
add $s0,$zero,$t3
j end
next:
add $s0,$t1,$t2
end:
Register Value 4
20. Write MIPS code that adds a number in $t1 to the constant 100 and puts the
result into $t3.
21. Write MIPS code that does the computation:
F = A + (((B - C) + D) - E)
Assume that variable A is in register $t0, B is in register $t1, C is in register $t2,
D is in register $t3, E is in register $t4 and F is in register $t5 (the result).
ori $t0,$0,255
addi $t1,$t0,1
sll $t2,$t1,2
23. What is the value of $t2 after the code below is executed?
ori $t0,$0,512
slt $t1,$0,$t0
bne $t1,$0,L0
ori $t2,$0,1024
j L1
L0: ori $t2,$0,2048
L1: