Académique Documents
Professionnel Documents
Culture Documents
Fakhra Aftab
SE (CIS), Batch: 2012-13
PRACTICE QUESTIONS SET # 01
Q.1) Compile each of the following C program fragments into MIPS assembly. Also provide the MIPS
machine code. Assume the following variable- register associations:
a $s0
b $s1
c $s2
Base Address of A
$s3
a. A[12] = b + A[8]
b. for (a = 0; a < 4; a++)
b = b + c;
c. for (a = 0; a <= 10; a++)
b = b + c;
d. if (a < b)
b = b + c;
b--;
e. if (a == b)
a--;
else
b--;
b += c;
f. c = a + (b-2);
Q.2) What MIPS instruction does this represent?
0 8 9 10 0 34
Q.3) Explore writing while loop in MIPS. Write MIPS Assembly & Machine code. (Section 2.7, 4
th
Ed)
while (save[i] == k)
i+=1;
Assume i & k are associated with $s3 and $s5 and the base of array save is in $s6.
Q.4) Explore compiling a String Copy (strcpy) Procedure. Write MIPS Assembly. (Section 2.9, 4
th
Edition)
void strcpy (char x[ ], char y[ ])
{
int i;
i = 0;
while ((x[i] = y[i]) != \0)
i+=1;
}
Q.5) Write down the sequence of MIPS instructions that will swap the contents of $s0 & $s1 making use
of lw & sw.
Q.6) Show how the data in the table would be arranged in memory of a little endian and big endian
machines. Assume data is stored starting at address 0x00002009.
Computer Organization & Design (CS-212) Course Instructor: Ms. Fakhra Aftab
SE (CIS), Batch: 2012-13
a 0xabcdef12
b 0x10203040
Q.7) A branch instruction beq is located at address 0x00801200. If its offset field contains 0xFFF0, what is
the address of the target instruction?
Q.8) Suppose that the instruction j 48 is located at address 0x104003C0. Find target address of this
instruction.
Q.9) Explore the logical operations (sll, srl, and, or, nor) in MIPS in detail. (Section 2.6, 4
th
Ed)
Q.10) You are required to perform several MIPS logical operations. Initial values of temporaries are as
follows:
a. $t0 = 0xAAAAAAAA, $t1 = 0x12345678
b. $t0 = 0xF00DD00D, $t1 = 0x11111111
Give value of $t2 after execution of each instruction.
sll $t2, $t0, 44
or $t2, $t0, $t1
sll $t2, $t0, 4
andi $t2, $t1, 1
srl $t2, $t0, 3
andi $t2, $t1, 0xFFEF
Instructions:
Attempt all questions.
Use A4 papers.
Assignment is on individual basis & it should be hand written.
Do mention your name, roll#, section, batch properly.
Assignment submission will be required on a day notice. Due date will be announced later.