Instruction Set - Computer Engineering - Solved Exam, Exams of Computer Science

Main points of this past exam are: Instruction Set, Factorialize This, Registers Described, Branch Predicate Register, Stack Pointer, Return Address, Code Fragment, Program Fragment, Datapath Elements, Determine the Output

Typology: Exams

2012/2013

Uploaded on 04/08/2013

sawardekar_984
sawardekar_984 🇮🇳

4.6

(10)

95 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 2030 10:00am Computer Engineering Fall 2002
5 problems, 5 pages Final Exam Solutions 9 December 2002
Problem 1 (1 part, 30 points) Factorialize This
In this problem, you will write a recursive procedure that computes factorial. Use only the
registers described in the table below. You should not require any registers in addition to those
listed. Your answer should fit in the boxes provided. Be sure to provide comments. The
instruction set is listed in a table on the following page.
register description register description
$0 zero (immutable) $3 branch predicate register
$1 input value $30 stack pointer
$2 output value $31 return address
To begin, define a push and pop stack macro below. Use $x to denote the value being preserved.
label instruction comment
Push
($
x
)
sw
$
x
,
($
30
)
store
$
x on stack
addi
$
30
,
$
30
,
4 increment stack
p
ointer
Po
p
($
x
)
addi
,
$
30
,
-4 decrement stack
p
ointer
lw
$
x
($
30
)
load
$
x from stack
Write a code fragment that initializes the result to 1 and then skips to label Done: if the input is
less than 2. The code fragment implementing Done: will be defined later.
label instruction comment
Fact: addi
$
2
,
$
0
,
1initialize result to 1
slti
$
3
,
$
1
,
2com
p
are in
p
ut to 2
bne
$
3
,
$
0
,
Done ski
p
to end if < 2
Write a code fragment that preserves the input value and return address on the stack. Then
decrement the input value and recursively call Fact:. Use the stack macros defined previously.
label instruction comment
p
ush
(
$
1
)
p
reserve in
p
ut on stack
p
ush
(
$
31
)
p
reserve return on stack
addi
$
1
,
$
1
,
-1 decrement in
p
ut
j
al Fact recursivel
y
call Fact
Write a code fragment that restores the input value and return address. Compute the result and
return from this subroutine. The label Done: should be defined here.
label instruction comment
p
o
p
($
31
)
restore return
p
o
p
($
1
)
restore in
p
ut
mul
2
2
1fact
(
i
)
=I*fact
(
i-1
)
Done:
j
r
$
31 return
1
pf3
pf4
pf5

Partial preview of the text

Download Instruction Set - Computer Engineering - Solved Exam and more Exams Computer Science in PDF only on Docsity!

5 problems, 5 pages Final Exam Solutions 9 December 2002

Problem 1 (1 part, 30 points) Factorialize This In this problem, you will write a recursive procedure that computes factorial. Use only the registers described in the table below. You should not require any registers in addition to those listed. Your answer should fit in the boxes provided. Be sure to provide comments. The instruction set is listed in a table on the following page.

register description register description $0 zero (immutable) $3 branch predicate register $1 input value $30 stack pointer $2 output value $31 return address

To begin, define a push and pop stack macro below. Use $x to denote the value being preserved.

label instruction comment Push ($x) sw $x, ($30) store $x on stack addi$30, $30, 4 increment stack pointer Pop ($x) addi, $30, -4 decrement stack pointer lw $x ($30) load $x from stack

Write a code fragment that initializes the result to 1 and then skips to label Done: if the input is less than 2. The code fragment implementing Done: will be defined later.

label instruction comment Fact: addi $2, $0, 1 initialize result to 1 slti $3, $1, 2 compare input to 2 bne $3, $0, Done skip to end if < 2

Write a code fragment that preserves the input value and return address on the stack. Then decrement the input value and recursively call Fact:. Use the stack macros defined previously.

label instruction comment push ($1) preserve input on stack push ($31) preserve return on stack addi $1, $1, -1 decrement input jal Fact recursively call Fact

Write a code fragment that restores the input value and return address. Compute the result and return from this subroutine. The label Done: should be defined here.

label instruction comment pop ($31) restore return pop ($1) restore input mul $2, $2, $1 fact(i)=I*fact(i-1) Done: jr $31 return

5 problems, 5 pages Final Exam Solutions 9 December 2002

Problem 2 (5 parts, 28 points) “You call this code?!” Consider the following MIPS program fragment. The instruction set is listed below.

address label instruction 1000 ori $1, $0, 0x 1004 here: jal zippy 1008 xor $2, $2, $ 1012 xor $3, $2, $ 1016 xor $2, $2, $ 1020 jal zappy 1024 addi $1, $1, - 1028 bne $1, $0, here Part A (7 points) What is the branch offset (in bytes) for the bne instruction?

branch offset (in bytes): -7 x 4 = - Part B (7 points) What is the value of register 1 (in decimal) after the ori completes?

value of $1 (in decimal): 128 Part C 7 points) What is the effect of instructions 1008, 1012, and 1016?

exchange contents of $2 and $

Part D (7 points) How many times is zippy called in this fragment?

number of zippy calls: 128/16 = 8

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 | $ and immediate andi $1,$2,100 $1 = $2 & 100 or immediate ori $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, 5 pages Final Exam Solutions 9 December 2002

Problem 4 (3 parts, 30 points) “Thanks for the memories”

Part A (10 points) Using a two-to-one mux, implement a transparent latch using basic gates (NAND, NOR, AND, OR, NOT, pass). Try to minimize transistors.

Part B (10 points) Now using a two-to-one mux and two transparent latches, implement a register with read and write enable using basic gates (NAND, NOR, AND, OR, NOT, pass).

Part C (10 points) Design a toggle cell using transparent latches and gates. Include an active high toggle enable TE, active low clear CLR, and a two-phase non-overlapping clock PHI1 and PHI2. Label the output OUT.

In Out

En

Latch

In Out

En

Latch

TE Out

CLR

5 problems, 5 pages Final Exam Solutions 9 December 2002

Problem 5 (3 parts, 30 points) Implementation Vacation

Consider the following expression:

Out = ( A + B + C )⋅( B + C )⋅ A

Part A (10 points) Implement the expression using only NOR and NOT gates. Assume you do not have the compliments of the inputs. Use proper mixed logic notation. Do not simplify the expression.

Out

A B C B C A

Part B (10 points) Now simplify the expression and produce a sum of products SOP expression. List all prime implicants and indicate which are essential.

A

A

B B

C

C

C

prime implicants

essential? yes no

A B C A B C

simplified SOP expression (^) ABC + ABC

Part C (10 points) Implement a two-input even parity gate using N and P type switches. Assume the inputs, X and Y, are available in their true and complemented forms.

A

B

A

B

A

A

B

B

Out