MIPS Final Exam Solutions for ECE 2030 - Fall 2003, Exams of Computer Science

The solutions to the final exam of the computer engineering course ece 2030, held in fall 2003. It includes answers to various problems related to mips assembly language, arithmetic operations, microcode reverse engineering, and instruction formats.

Typology: Exams

2012/2013

Uploaded on 04/08/2013

savitri_122
savitri_122 🇮🇳

4.6

(14)

184 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 2030 10:00am Computer Engineering Fall 2003
5 problems, 6 pages Final Exam Solutions 11 December 2003
1
Problem 1 (2 parts, 45 points) Assembly Language Fun
Part A (25 points) An unknown program is listed below. Answer the following questions about
its behavior. The MIPS ISA description is provided on the next page.
label instruction
Push ($x) sw $x, ($30)
addi $30, $30, 4
Pop ($x) addi $30, $30, -4
lw $x, ($30)
Foo: add $2, $0, $0
beq $1, $0, Done
push ($1)
push ($31)
addi $1, $1, -1
jal Foo
pop ($31)
pop ($1)
add $2, $2, $1
Done: jr $31
If $1 = 10 when Foo is called, what will $2 be when the subroutine finally completes?
$2 after Foo completes: 10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 = 55
How many instructions in this subroutine are executed when called with $1 = 10?
instructions executed: 10 x 14 + 1 x 3 = 143 instructions
What is the maximum size of the stack when this subroutine is called with $1 = 10?
Maximum stack size (in words): 10 x 2 = 20 words
What is the branch offset (in bytes) for the BEQ instruction?
Branch offset (in bytes): +11 x 4 = +44
What is the maximum number of different return addresses (non-identical addresses) that are
stored in the stack when this subroutine is called?
Maximum unique return addresses in stack: 2
pf3
pf4
pf5

Partial preview of the text

Download MIPS Final Exam Solutions for ECE 2030 - Fall 2003 and more Exams Computer Science in PDF only on Docsity!

5 problems, 6 pages Final Exam Solutions 11 December 2003

Problem 1 (2 parts, 45 points) Assembly Language Fun

Part A (25 points) An unknown program is listed below. Answer the following questions about its behavior. The MIPS ISA description is provided on the next page.

label instruction Push ($x) sw $x, ($30) addi $30, $30, 4

Pop ($x) addi $30, $30, - lw $x, ($30)

Foo: add $2, $0, $ beq $1, $0, Done push ($1) push ($31) addi $1, $1, - jal Foo pop ($31) pop ($1) add $2, $2, $ Done: jr $

If $1 = 10 when Foo is called, what will $2 be when the subroutine finally completes?

$2 after Foo completes: 10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 = 55

How many instructions in this subroutine are executed when called with $1 = 10?

instructions executed: 10 x 14 + 1 x 3 = 143 instructions

What is the maximum size of the stack when this subroutine is called with $1 = 10?

Maximum stack size (in words): (^) 10 x 2 = 20 words

What is the branch offset (in bytes) for the BEQ instruction?

Branch offset (in bytes): +11 x 4 = +

What is the maximum number of different return addresses (non-identical addresses) that are stored in the stack when this subroutine is called?

Maximum unique return addresses in stack: 2

5 problems, 6 pages Final Exam Solutions 11 December 2003

Part B (20 points) Write a subroutine that computes the absolute value of the contents of $1, leaving the result in $2. Use $3 as a predicate register. $1 should be unchanged following this subroutine.

label instruction comment ABS: add $2, $1, $0 copy $1 to $ slt $3, $1, $0 if $2 >= 0, $3 = 0 beq $3, $0, Skip skip if non-negative sub $2, $0, $1 else $2 = -$ jr $31 return to caller

instruction example meaning add add $1,$2,$3 $1 = $2 + $ subtract sub $1,$2,$3 $1 = $2 - $ add immediate addi $1,$2,100 $1 = $2 + 100 multiply mul $1,$2,$3 $1 = $2 * $ divide div $1,$2,$3 $1 = $2 / $ and and $1,$2,$3 $1 = $2 & $ or or $1,$2,$3 $1 = $2 | $ xor xor $1,$2,$3 $1 = $2 xor $ and immediate andi $1,$2,100 $1 = $2 & 100 or immediate ori $1,$2,100 $1 = $2 xor 1 xor immediate xori $1,$2,100 $1 = $2 | 100 shift left logical sll $1,$2,5 $1 = $2 << 5 (logical) shift right logical srl $1,$2,5 $1 = $2 >> 5 (logical) shift left arithmetic sla $1,$2,5 $1 = $2 << 5 (arithmetic) shift right arithmetic sra $1,$2,5 $1 = $2 >> 5 (arithmetic) load word lw $1, ($2) $1 = memory [$2] store word sw $1, ($2) memory [$2] = $ load upper immediate lui $1,100 (^) $1 = 100 x 2 16 branch if equal beq $1,$2,100 if ($1 = $2), PC = PC + 4 + (1004) branch if not equal bne $1,$2,100 (^) if ($1 ≠ $2), PC = PC + 4 + (1004) set if less than slt $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0 set if less than immediate slti $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0 jump j 10000 PC = 10000* jump register jr $31 PC = $ jump and link jal 10000 $31 = PC + 4; PC = 10000*

5 problems, 6 pages Final Exam Solutions 11 December 2003

Problem 3 (3 parts, 30 points) Reverse Engineering

For each part below (10 points, 8 points, 12 points), determine the behavior and write as a Boolean expression. A

B

C

D

E

OUTx

OUTy

OUTx = (^) A + BC

OUTY = (^) BC ⋅( D + E )

A B C

D E

A

B

D

C E

OUTz

OUTZ = ( A + B )⋅ D + C ⋅ E

φ 1 φ 2

OUT

A B

A B CLK OUT

0 1 ↑↓ Q 0

1 1 ↑↓ ¬ Q 0

hint: look for muxes

5 problems, 6 pages Final Exam Solutions 11 December 2003

Problem 4 (5 parts, 30 points) Microcode Reverse Engineering

The microcode fragment below comes from a color scanner control program that runs on the datapath discussed in class. For each question below, describe the meaning of the specified microcode cycle. Unfortunately, don’t care values (X) have been converted to zeros. For maximum points, be as specific and concise as you can (e.g., list shift types, amounts, and directions, logical functions, memory addresses and operations, etc.)

cycle X Y Z rwe im en im va au en -a/s lu en lf su en st ld en st en r/-w msel 1 0 0 3 1 1 100 0 0 1 C 0 0 0 0 0 0 2 3 0 0 1 0 0 0 0 0 0 0 0 1 0 1 1 3 0 0 2 1 1 FF 0 0 1 8 0 0 0 0 0 0 4 0 0 0 1 1 8 0 0 0 0 1 0 0 0 0 0 5 0 0 1 1 1 FF 0 0 1 8 0 0 0 0 0 0 6 1 2 2 1 0 0 1 0 0 0 0 0 0 0 0 0 7 0 0 0 1 1 8 0 0 0 0 1 0 0 0 0 0 8 0 0 1 1 1 FF 0 0 1 8 0 0 0 0 0 0 9 1 2 2 1 0 0 1 0 0 0 0 0 0 0 0 0 10 0 0 0 1 1 8 0 0 0 0 1 0 0 0 0 0 11 0 2 2 1 0 0 1 0 0 0 0 0 0 0 0 0 12 2 0 2 1 1 2 0 0 0 0 1 1 0 0 0 0 13 3 2 0 0 0 0 0 0 0 0 0 0 0 1 0 1

Part A (5 points) Describes the operation that occurs during cycle 2 (be specific).

r0  mem[r3 (0x100)] For the remaining parts, assume $0 = 0x81422418 at the end of cycle 2.

Part B (5 points) What is the value of register 0 at the completion of cycle 7 (in hexadecimal).

8142 Part C (5 points) What is the value of register 2 at the completion of cycle 9 (in hexadecimal).

42 + 24 + 18 = 7E Part D (5 points) What is the value of register 2 at the completion of cycle 12 (in hexadecimal).

FF >> 2 = 3F Part E (10 points) Describes the operation of this microcode fragment (be specific).

computes the average of for packed eight bit fields at mem[100] and writes result