0% found this document useful (0 votes)
29 views2 pages

Quiz 1 Goal 4 (1, 5, 6) 5 5

The document contains two quiz questions and their solutions related to MIPS assembly code. Question 1 asks about the steps for a procedure in MIPS and is answered with 6 steps. Question 2 asks about instruction formats in MIPS but the response is not shown. The second document contains another two quiz questions. Question 1 asks for the MIPS code for a C assignment statement involving array indexing and addition, and is answered with 3 lines of MIPS code. Question 2 asks for the MIPS code for a C conditional statement involving variable assignment, and is answered with 4 lines of MIPS code comparing registers and branching.

Uploaded by

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

Quiz 1 Goal 4 (1, 5, 6) 5 5

The document contains two quiz questions and their solutions related to MIPS assembly code. Question 1 asks about the steps for a procedure in MIPS and is answered with 6 steps. Question 2 asks about instruction formats in MIPS but the response is not shown. The second document contains another two quiz questions. Question 1 asks for the MIPS code for a C assignment statement involving array indexing and addition, and is answered with 3 lines of MIPS code. Question 2 asks for the MIPS code for a C conditional statement involving variable assignment, and is answered with 4 lines of MIPS code comparing registers and branching.

Uploaded by

ranaateeq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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:

You might also like