Sei sulla pagina 1di 2

Quiz 1

Goal 4 (1, 5, 6)

Q.1 Write down all steps for procedure in MIPS. 5


Q.2 Explain the all types of instruction format. 5

Q.1 Write down all steps for procedure in MIPS.


Solution
Place parameters in a place where the procedure can access them.
2. Transfer control to the procedure.
3. Acquire the storage resources needed for the procedure.
4. Perform the desired task.
5. Place the result value in a place where the calling program can access it.
6. Return control to the point of origin, since a procedure can be called from several points in a
program.

Q.2 Explain the all types of instruction format.

Solution
Quiz 2
Goal 4 (2, 3, 4)

Q.1 Assume variable h is associated with register $s2 and the base address of the array A is in
$s3. What is the MIPS assembly code for the C assignment statement below?
A[12] = h + A[8]; 5

Q.2 In the following code segment, f, g, h, i, and j are variables. If the five variables f through j
correspond to the five registers $s0 through $s4, what is the compiled MIPS code for this C
statement?
if (i == j) f = g + h; else f = g – h; 5

Q.1 Assume variable h is associated with register $s2 and the base address of the array A is in
$s3. What is the MIPS assembly code for the C assignment statement below?
A[12] = h + A[8];

Solution

lw $t0,32($s3) # Temporary reg $t0 gets A[8]


add $t0,$s2,$t0 # Temporary reg $t0 gets h + A[8]

The final instruction stores the sum into A[12], using 48 as the offset and register $s3 as the base register.

sw $t0,48($s3) # Stores h + A[8] back into A[12]

Q.2 In the following code segment, f, g, h, i, and j are variables. If the five variables f through j
correspond to the five registers $s0 through $s4, what is the compiled MIPS code for this C
statement?
if (i == j) f = g + h; else f = g – h;

Solution

bne $s3,$s4,Else # go to Else if i = j

bne $t0,$s5, Exit # go to Exit if save[i] = k

The next instruction adds 1 to i:

add $s3,$s3,1 #i=i+1

The end of the loop branches back to the while test at the top of the loop. We just add the Exit label
after it, and we’re done:
j Loop # go to Loop
Exit:

Potrebbero piacerti anche