



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!




This was an 85-minute open-book test. You were to answer five of the six questions. Each question was worth 20 points. If you answered all six questions, your five highest scores counted.
Question 1. The program at the left, below, is written for a 0-address machine. Rewrite it for a 1 - address, 2-address, and 3-address machine (8, 7, and 5 points, respectively). The first few instructions are done for you. 0 - address 1 - address 2 - address 3 - address PUSH A PUSH B MUL POP C PUSH C PUSH B ADD POP D PUSH A PUSH C SUB POP A PUSH D PUSH A DIV POP E
Question 2. Each instruction below contains a mode field, which specifies the addressing mode, and a register field which may refer to an index register. The LOAD instruction loads an accumulator, and ADD adds a value to the accumulator. Opcode Mod e Reg. Operand LOAD?? 20 Opcode Mod e Reg. Operand ADD?? 22
Here is a table of mode-field values and their meanings:
Address 20 21 22 23 24 25 26 27 28 29 30 Contents 30 210 20 25 24 10 260 30 280 25 27
Also, assume index register 1 contains 5. (3 points each) What is the value in the accumulator after execution of the LOAD and ADD instructions if— (a) Both mode fields contain 1, and no index register is specified? Answer: 20+22 = 42 (b) Both mode fields contain 2, and no index register is specified? Answer: 30+20 = 50 (c) Both mode fields contain 3, and no index register is specified? Answer: 27+30 = 57 (d) Both mode fields contain 4, and index register 1 is specified? Answer: 10+30 = 40 (e) Both mode fields contain 5, and index register 1 is specified? Answer: 10+280= (f) (5 points) The Burroughs B6700 (a computer from the 1970s) had no special indirect operand formats; however, if a memory reference retrieves a word marked as “indirect,” then an indirect reference will be performed. What serious problem can occur if a programmer is careless about where his “indirect” words point? You may wish to illustrate the problem using the memory contents above. Answer: The problem is that we can get in an infinite loop doing indirect references. For example, suppose that word 24 in the example above has its indirect bit set. That causes it to be fetched again, and again, ad infinitum. The same thing happens if bits 30 and 27 have their indirect bits set. This is serious indeed, because there may be no way to interrupt an instruction in the middle of fetching an operand. Then there is no way to recover from this error, except by rebooting the computer!
Question 3. Consider this program fragment, expressed in a higher-level language and in assembly language. ( Note the correction in the first ADDI instruction below). ADDI R8,R0,# for ( i = 1; i <= 9; i++) ADDI R1, R0, # { LOOP1 {9 instructions} /* 9 instructions */ ADDI R1,R1,# } BNE R1,R8,LOOP (a) (7 points) Suppose that this code is executed on a processor with a 4-stage static pipeline (each instruction takes 4 pipeline cycles to execute) and no branch prediction. No branch target is fetched until the branch gets all the way through the pipeline. What is the execution time, in pipeline cycles? (Assume each instruction takes an equal amount of time.) Answer: The loop consists of 11 instructions, including the ADDI and BNE at the end. The loop is executed 9 times. Hence there are 9 ∞ 11 instructions executed in the loop, plus two for loop initialization, for a total of 101 instructions altogether. Of these 101 instructions, 8 are taken branches. If there were no branches at all, it would take 101 + (4 – 1) = 104 pipeline cycles to execute this code. Each taken branch wastes 4 – 1 = 3 cycles. Therefore, it takes 104 + 8∞3 = 128 cycles to execute this program fragment.
Answer: The branch will be predicted not taken. The prediction will never be wrong, unless it happens that the branch is taken twice in a row (unlikely if it is only taken 0.1% of the time). (b) Now assume the prediction is made by a branch target buffer (Lecture 15), using a single prediction bit for each branch, with so few entries that the LOOP2 and LOOP3 branches conflict in the table. (i) What prediction will we make for the branch associated with LOOP2? After a learning period, approximately what percentage of the time will this prediction be wrong? Answer: The branch will be predicted taken on the second, third, and fourth iteration of the inner loop, not taken on the first. This will be wrong 2 times out of 4, or 50%. (ii) What prediction will we make for the branch associated with LOOP3? After a learning period, approximately what percentage of the time will this prediction be wrong? Answer: The branch will be predicted not taken about 99.9% of the time. The prediction will be wrong about 0.2% of the time (the 0.1% of the time that the branch is taken, and the 0.1% of the time following the time that the branch was taken). The interference of the LOOP branch doesn't have much effect, because it causes the 1-bit predictor to predict not taken the time after execution falls through at the end of LOOP2. (iii) What does the fact that the LOOP2 and LOOP3 branches conflict tell us about the table size? (Assume that address bits are used to index into the table.) Answer: Lopping off bits 1:0 of the address yields an index of 32 for the LOOP2 branch and 64 for the LOOP3 branch. If there are 32 or fewer entries in the table, the branches will conflict.
Question 5. (4 points each) How many total bits are needed for the following branch predictors? Include—
Answer: 2 a^ + 1 +1 bit: One bit of global history, and two one-bit predictors in each of the 2^ a entries. (b) The gshare predictor given as on p. 3 of Lecture 16 (the one that predicts branches A and D). Answer: 18 bits, 2 for the global history register and 16 for eight two-bit counters. (c) The ( m, n ) gshare branch predictor described on p. 4 of Lecture 16, where a bits of the address are used, along with the global history, to select a predictor. (You may assume that a < m.)
Answer: 2 m n + m. The m is for the global history register, the 2^ m^ n for the counters. Since a < m, and the address bits are exclusive- or ed with the global history, there are a total of 2^ m counters. (d) An ( m, n ) predictor implemented as a linear array that is m bits wide (as described on p. 5 of the notes), using a bits of the address to select a predictor.
Answer: 2 m^ +^ a^ n + m. For each of the 2^ m entries, there are 2^ a counters. (e) A Yeh-Patt predictor, using a bits of the address, m bits of history and 2-bit counters Answer: m 2 a + 2^ m^ + 1. The history table contains 2^ a^ m-bit counters, and the pattern table contains 2 m t w o - bit counters.
Quartiles (70, 78, 86)
ECE 463 average was 78.08; ECE 521 average was 76.62.