


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



5 problems, 4 pages Final Exam Solution 14 December 2006
Problem 1 (3 parts, 27 points) Microcode
Using the supplied datapath, write microcode fragments to accomplish the following procedures. Express all values in hexadecimal notation. Use ‘X’ when a value is don’t cared. For maximum credit, complete the description field. Recall that ⊕ means XOR. Use only registers 1, 2, and 3.
Part A (15 points) 8
1
# X Y Z rwe im en
im va au en
-a /s
lu en
lf su en
st description
(^1 2 3 2 1 0) X 0 X 1 6 0 X R2 <- R2 xor R
(^2 1) X 1 1 1 FFFE 0 X 0 X 1 1 R1 <- R1 * 4
(^3 1 2 1 1 0) X 1 0 0 X 0 X R1 <- R2 + R
(^4 1) X 1 1 1 0005 1 1 0 X 0 X R1 <- R1 - 5
(^5 1) X 1 1 1 0003 0 X 0 X 1 1 R1 <- R1 / 8
Part B (6 points) Assume R 1 contains three packed unsigned integer bytes (A, B, and C). Assume A is the least significant byte, then B, then C. Write a microcode fragment that unpacks B, placing it in the lowest eight bits of R 1. All other bits should be zero. # X Y Z rwe im en
im va au en
-a /s
lu en
lf su en
st description
(^1 1) X 1 1 1 0008 0 X 0 X 1 0 R1 <- R1 >> 8
(^2 1) X 1 1 1 00FF 0 X 1 8 0 X R1 <- R1 & FF
Part C (6 points) Write a microcode sequence that averages the initial values of R 1 and R 2. The result should be placed in R 1. # X Y Z rwe im en
im va au en
-a /s
lu en
lf su en
st description
(^1 1 2 1 1 0) X 1 0 0 X 0 X R1 <- R1 + R
(^2 1) X 1 1 1 0001 0 X 0 X 1 1 R1 <- R1 / 2
5 problems, 4 pages Final Exam Solution 14 December 2006
Problem 2 (4 parts, 32 points) MinMax Redux
In this problem, you are given a subroutine that computes the minimum and maximum value of an array of integers. The address of the first and last elements of the array are stored in $1 and $ before the subroutine is called. The min and max are returned in $3 and $4 respectively. register inputs register outputs $1 address of first element $3 min value $2 address of last element $4 max value
address label instruction 1000 MinMax: lw $3, ($1) 1004 lw $4, ($1) 1008 Loop: lw $5, ($1) (^1012) slt $6, $5, $ 1016 beq $6, $0, Skip 1020 add $3, $5, $ 1024 Skip1: slt $6, $4, $ 1028 beq $6, $0, Skip 1032 add $4, $5, $ 1036 Skip2: addi $1, $1, 4 1040 slt $6, $2, $ 1044 beq $6, $0, Loop 1048 jr $
Part A (6 points) What is the branch offset (in bytes) for the beq instruction at 1044?
branch offset (in bytes): -10 instructions x 4 bytes/I = -40 bytes
Part B (8 points) Write an expression for the number of times the loop body is executed in terms of $1 and $2?
Times Loop: executed = ($2 - $1 + 4) / 4
Part C (12 points) Write a block of code that calls MinMax, passing in a 100 integer array that starts at 5000. When the subroutine returns, use the min and max to compute the value range (max – min) storing the value in $5. label instruction comment addi $1, $0, 5000 # load first address add $2, $1, 396 # load last address jal MinMax # call min max subroutine sub $5, $4, $3 # compute min max delta
Part D (6 points) Suppose a jal instruction occurs at address 2024. What is the value of $ following the instruction’s execution?
$31 = 2024 + 4 = 2028
5 problems, 4 pages Final Exam Solution 14 December 2006
Problem 5 (3 parts, 30 points) Reverse Engineering
For each part below, determine the behavior and write as a Boolean expression.
A
B C
E
OUTX
D OUTY
OUTx = A ⋅( B ⋅ C )
Outz
A