



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: Iterative Factorial, Factorial Redux, Computer Engineering, Factorial Program, Instructions Executed, Subroutine, Instructions Executed, Different Return, Addresses in Stack, Factorial Program
Typology: Exams
1 / 6
This page cannot be seen from the preview
Don't miss anything!




5 problems, 7 pages Final Exam Solution 30 April 2003
Problem 1 (1 parts, 45 points) Factorial Redux
Part A (25 points) A recursive factorial 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)
Fact: addi $2, $0, 1 slti $3, $1, 2 bne $3, $0, Done push ($1) push ($31) addi $1, $1, - jal Fact pop ($31) pop ($1) mul $2, $2, $ Done: jr $
How many instructions in this subroutine are executed when called with an input value of -3?
instructions executed: 4
How many instructions in this subroutine are executed when called with an input value of 5?
instructions executed: 64
What is the maximum size of the stack when this subroutine is called with an input value of 10?
maximum stack size (in words): (^) 9 x 2 = 18
What is the branch offset (in bytes) for the BNE instruction?
branch offset (in bytes): +11 x 4 = 44
What is the maximum number of different return addresses (non-identical address) that are stored in the stack when this subroutine is called?
maximum unique return addresses in stack: 2
5 problems, 7 pages Final Exam Solution 30 April 2003
Part B (20 points) Now write an iterative factorial program that observes the same conventions as the given recursive program.
label instruction comment Fact: ADDI $2, $0, 1 initialize result to 1 Loop: SLTI $3, $1, 2 test input < 2 BNE $3, $0, Done skip if done MUL $2, $2, $1 multiply with result ADDI $1, $1, -1 Decrement input BEQ $1, $0, Loop loop if non-zero Done: 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 xori $1,$2,100 $1 = $2 xor 1 xor 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, 7 pages Final Exam Solution 30 April 2003
Problem 3 (2 parts, 26 points) Karnaugh Maps
Part A (13 points) For the follow expression, derive a simplified product of sums expression using a Karnaugh Map. Circle and list the prime implicants, indicating which are essential.
Out = B โ C โ D + A โ B โ D + A โ B โ C โ D + A โ C โ D
prime implicants
essential? yes no
simplified POS expression D โ ( B + C )
Part B (13 points) For the follow expression, derive a simplified sum of products expression using a Karnaugh Map. Circle and list the prime implicants, indicating which are essential.
Out =( A + B + D )โ ( B + C + D )โ ( A + B + D )โ ( A + C + D )โ ( A + B + C )
prime implicants
essential? yes no
simplified SOP expression (^) B โ D + A โ B โ C + A โ B โ C + A โ D or B โ D + A โ B โ C + A โ B โ C + C โ D
5 problems, 7 pages Final Exam Solution 30 April 2003
Problem 4 (3 parts, 35 points) Instruction Formats
Part A (15 points) Consider the instruction set architecture below with fields containing zeros. 0000 0000 0000 0000 0000 0000 0000 0000 opcode dest. reg. source 1 reg. immediate value What is the maximum number of opcodes? 16 What is the number of registers? (^) 256
What is the range of the signed immediate value? ยฑ2K
Part B (12 points) List three differences between a branch and a jump in the MIPS instruction set.
1: Branches are relative; jumps are absolute. 2: Branch targets can ยฑ32K instructions from branch, Jump targets are 0 to 64M 3: Branches are conditional; Jumps are unconditional.
Part C (8 points) Explain the need for byte addressing in todayโs microprocessors?
Byte addressing is needed to support: character pointers, byte stream file I/O