



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 5
This page cannot be seen from the preview
Don't miss anything!




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
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 (^) A ⋅ B ⋅ C + A ⋅ B ⋅ C
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