S2 Fall 28 Final Prep and super secret quiz 9 ) onvert 8-bit (2-digit) 2 s complement hex values: 4-29 inary: Hex: x29 2) onvert 8-bit 2 s complement hex to decimal: x3 inary: xe5 Decimal: 58 Note 3*6+ = 58 3) dd these hex numbers. Stay in hex! 9 +2 3E +4 55 +56 inary 29: Flip: + Hex: xe3 inary: Flip: +: Final binary is 27, so orig decimal is -27 +29 2 52 4) What are possible number ranges for a 7-bit integers for Unsigned? 2 s complement? Unsigned: to 27, 2 s comp is -64 to 63 5) reate a truth table for the following circuit. ND 6) ou have a circuit with inputs,, and. Design a circuit that produces if there are an odd number of s on the inputs.!! +!! +!! + Not much you can do with the Karnaugh map, but you could build the circuit with two XOR gates XOR XOR
7) Simplify the oolean equation = (+!)(+)() ((+!))(+)() ()(+)() ( + )() ((+)) ()() < simplified final version 8) ou need a 2-input OR gate, but you only have an ND gate and some inverters. Use your ND gate and inverters to make an OR gate. Final version OR OR NOT NOT NOR NOT OR gate with two inverters is the same as an OR. This lets us bubble push, or into an ND with inverted inputs 9) Show the truth table for the following finite state machine. S S is the current state, NS NS is the next state. The input is T, T S S NS NS x x x x ) onstruct a Karnaugh map, and show the simplified circuit for the following truth table. x!! + x NOR ND OR
) ou have a JL instruction at location x42488. Immediately after executing the JL, what value is in register $R? x42488 + 4 > x4248 2) Register $s is a POINTER to the start of an array of integers. ll values in the array are greater than zero, and the array is terminated by a zero. Write code and MIPS code to compute the sum of all the values in the array, leaving the sum in register $s. Version data[] = 3, 5, 99, ; int *s = data; // our code follows here int s = ; for (int i = ; s[i]!= ; ++i) s = s + s[i]; // lternate move pointers int s = ; while (*s!= ) s = s + *s; ++s; 3) Write MIPS assembly to add 8 to a value (passed as a pointer). The code looks like this. This is a subroutine. void add_eight(int *x) if (*x == ) *x = 8; else *x = *x + 5; MIPS Version la $s, data # s points to array # our code follows here # Move pointers # variation li $s, loop: lw $t, ($s) # Similar to top li $s, li $t, loop: # pointer t2 is # s + t*4 sll $t2, $t, 2 add $t2, $s, $t2 lw $t, ($t2) beq $t, $, done add $s, $s, $t # Increment i addi $t, $t, j loop 4) Write MIPS assembly for sub, a subroutine that calls two other subroutines. The code looks like this. This is also a subroutine. sub2 and sub3 are in a library. int sub(int a, int b) sub2(a); sub3(b); return 6; beq $t, $, done add $s, $s, $t # Move pointer add $s, $s, 4 j loop SEE NEXT PGE. The key has lots of comments, which you don t have to do for the exam.
void add_eight(int *x) if (*x == ) *x = 8; else *x = *x + 5; int sub(int a, int b) sub2(a); sub3(b); return 6; add_eight: # Get the pointer to X lw $t, ($sp) # Get the value indicated lw $t, ($t) # If statement here. check # if not equal bne $t, $, else_part # Use t, and pointer to change # value to 8 li $t, 8 sw $t, ($t) # IMPORTNT. Must jump past the # next few lines, to not do # the else section too! j done else_part: addi $t, $t, 5 sw $t, ($t) jr $ra # In this code, because there s no # jal call, it s OK to not save # R. If you save it cool, that s # not a bad thing to do but it s # not absolutely required sub: # Push R sw $ra, ($sp) # Get the lw $t, 4($sp) # Push on stack sw $t, ($sp) # all sub2 jal sub2 # Pop off stack # Get lw $t, 8($sp) # Push on stack sw $t, ($sp) # all sub3 jal sub3 # Pop off stack # Restore R lw $ra, ($sp) Return to whoever called us jr $ra
5) When a processor is not pipelined, different instructions might take different numbers of cycles. If a LW takes 5 cycles, an DD takes 4, and a RNH takes 2, and you have a program that is 5% LW instructions, 2% DD instructions, and 3% branch instructions, what is the average PI (cycles per instruction)? 5*.5 + 4*.2 + 2*.3 = 3.9 cycles per instruction, average 6) ou have a non-pipelined processor, with all instructions taking five steps, as shown below. The time required in terms of cycles is shown. Fetch 5 What s the PI? Decode 2 Execute 3 Memory 4 Write Reg 5 cycles per instruction. 5+2+3+4+ = 5 7) If you pipeline the microprocessor, how many cycles would a single instruction take? Slowest link is fetch, 5 cycles. 5 stages, 5 cycles each, 25 cycles 8) What are the effective average PI and IP of the pipelined processor (assuming no stalls, or pipeline flushing due to branches). PI = 5, IP = /5. 9) Name two types of hazards you might see on a pipelined microprocessor ontrol hazard (e.g., a jump needs a NOP after it), and data hazard (result stored in one register not available immediately) 2) Modify the code below so that it could run faster on a pipelined microprocessor. add $a, $a3, $a4 add $a, $a, $a lui $a3, 58 Swap last two instructions. $a in first instruction is not finished when second instruction that uses $a starts 2) onus question. Have you filled out the SOOT survey (secret answer is yes ) The final will ask what is the secret answer to the secret question, and you should say yes