ECE 411 Exam 1. This exam has 5 problems. Make sure you have a complete exam before you begin.

Similar documents
ECE 411 Exam 1. Name:

ISA Instruction Operation

ECE 411, Exam 1. Good luck!

Trap Vector Table. Interrupt Vector Table. Operating System and Supervisor Stack. Available for User Programs. Device Register Addresses

20/08/14. Computer Systems 1. Instruction Processing: FETCH. Instruction Processing: DECODE

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON. Instructor: Rahul Nayar TAs: Annie Lin, Mohit Verma

CS 2461: Computer Architecture I

Intro. to Computer Architecture Homework 4 CSE 240 Autumn 2005 DUE: Mon. 10 October 2005

ECE 411 Exam 1 Practice Problems

UNIVERSITY OF WISCONSIN MADISON

appendix a The LC-3 ISA A.1 Overview

The LC-3 Instruction Set Architecture. ISA Overview Operate instructions Data Movement instructions Control Instructions LC-3 data path

Memory Usage in Programs

Ch. 5: The LC-3. PC-Relative Addressing Mode. Data Movement Instructions. James Goodman!

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON. Instructor: Rahul Nayar TAs: Mohit Verma, Annie Lin

LC-3 Instruction Set Architecture

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

University of Illinois at Urbana-Champaign First Midterm Exam, ECE 220 Honors Section

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

ADD R3, R4, #5 LDR R3, R4, #5

10/31/2016. The LC-3 ISA Has Three Kinds of Opcodes. ECE 120: Introduction to Computing. ADD and AND Have Two Addressing Modes

ECE/CS 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING COMPUTER SCIENCES DEPARTMENT UNIVERSITY OF WISCONSIN-MADISON

Instruction Set Architecture

Computer Architecture CS372 Exam 3

LC-3 ISA - II. Lecture Topics. Lecture materials. Homework. Machine problem. Announcements. ECE 190 Lecture 10 February 17, 2011

CS 135: Computer Architecture I

EECS 470 Midterm Exam Winter 2015

Computer System Architecture Midterm Examination Spring 2002

EECS 470 Midterm Exam Winter 2008 answers

CPSC 313, Summer 2013 Final Exam Date: June 24, 2013; Instructor: Mike Feeley

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING COMPUTER SCIENCES DEPARTMENT UNIVERSITY OF WISCONSIN-MADISON

ECE/CS 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

LC-3 Instruction Set Architecture. Textbook Chapter 5

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Computing Layers

CMU Introduction to Computer Architecture, Spring Midterm Exam 1. Date: Wed., 3/6. Legibility & Name (5 Points): Problem 1 (65 Points):

EEL 5722C Field-Programmable Gate Array Design

CS 433 Homework 4. Assigned on 10/17/2017 Due in class on 11/7/ Please write your name and NetID clearly on the first page.

Write only as much as necessary. Be brief!

CPSC 313, Summer 2013 Final Exam Solution Date: June 24, 2013; Instructor: Mike Feeley

Computer Architecture and Engineering. CS152 Quiz #3. March 18th, Professor Krste Asanovic. Name:

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS 270 Fall 2013 Mock Final

1. Truthiness /8. 2. Branch prediction /5. 3. Choices, choices /6. 5. Pipeline diagrams / Multi-cycle datapath performance /11

Chapter 5 The LC-3. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University 5-2

ENGN 2910A Homework 03 (140 points) Due Date: Oct 3rd 2013

ELEC3441: Computer Architecture Second Semester, Homework 3 (r1.1) SOLUTION. r1.1 Page 1 of 12

Introduction to Computer Engineering. CS/ECE 252, Fall 2016 Prof. Guri Sohi Computer Sciences Department University of Wisconsin Madison

ECE 313 Computer Organization FINAL EXAM December 14, This exam is open book and open notes. You have 2 hours.

COSC121: Computer Systems: Review

Introduction to Computer Engineering. Chapter 5 The LC-3. Instruction Set Architecture

Register Files. Single Bus Architecture. Register Files. Single Bus Processor. Term Project: using VHDL. Accumulator based architecture

LC-2 Programmer s Reference and User Guide

Computing Layers. Chapter 5 The LC-3

ECE 109 Sections 602 to 605 Final exam Fall December, 2007

COSC121: Computer Systems: Review

6.823 Computer System Architecture Datapath for DLX Problem Set #2

Final Exam Spring 2017

EECS 470 Midterm Exam

OPEN BOOK, OPEN NOTES. NO COMPUTERS, OR SOLVING PROBLEMS DIRECTLY USING CALCULATORS.

Final Exam Fall 2007

SOLUTION. Midterm #1 February 26th, 2018 Professor Krste Asanovic Name:

Computer Architecture and Engineering CS152 Quiz #2 March 7th, 2016 Professor George Michelogiannakis Name: <ANSWER KEY>

Introduction to Computer. Chapter 5 The LC-3. Instruction Set Architecture

c. What are the machine cycle times (in nanoseconds) of the non-pipelined and the pipelined implementations?

Binghamton University. CS-120 Summer LC3 Memory. Text: Introduction to Computer Systems : Sections 5.1.1, 5.3

LC-3 Instruction Processing

CS 2410 Mid term (fall 2015) Indicate which of the following statements is true and which is false.

The University of Michigan - Department of EECS EECS 370 Introduction to Computer Architecture Midterm Exam 2 solutions April 5, 2011

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. April 12, 2018 L16-1

Chapter 4 The Von Neumann Model

Load -- read data from memory to register. Store -- write data from register to memory. Load effective address -- compute address, save in register

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. November 15, MIT Fall 2018 L20-1

ECE Sample Final Examination

Chapter 4 The Von Neumann Model

Name: University of Michigan uniqname: (NOT your student ID number!)

LC-3 Instruction Processing. (Textbook s Chapter 4)

Computer Architecture V Fall Practice Exam Questions

Computer System Architecture Quiz #1 March 8th, 2019

Exam-2 Scope. 3. Shared memory architecture, distributed memory architecture, SMP, Distributed Shared Memory and Directory based coherence

Computer Architecture EE 4720 Final Examination

Introduction to Computer Engineering. CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison

EN2910A: Advanced Computer Architecture Topic 02: Review of classical concepts

Introduction to Computer Engineering. CS/ECE 252, Fall 2016 Prof. Guri Sohi Computer Sciences Department University of Wisconsin Madison

Pipelined processors and Hazards

Introduction to Computer Engineering. CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison

Memory Hierarchy. Mehran Rezaei

Midterm #2 Solutions April 23, 1997

Department of Electrical and Computer Engineering The University of Texas at Austin

That is, we branch to JUMP_HERE, do whatever we need to do, and then branch to JUMP_BACK, which is where we started.

Question 1 (5 points) Consider a cache with the following specifications Address space is 1024 words. The memory is word addressable The size of the

Department of Electrical and Computer Engineering The University of Texas at Austin

Virtual Memory Worksheet

6.004 Tutorial Problems L20 Virtual Memory

(1) Using a different mapping scheme will reduce which type of cache miss? (1) Which type of cache miss can be reduced by using longer lines?

Department of Electrical and Computer Engineering The University of Texas at Austin

Chapter 5 - ISA. 1.The Von Neumann Model. The Stored Program Computer. Von Neumann Model. Memory

Transcription:

This exam has 5 problems. Make sure you have a complete exam before you begin. Write your name on every page in case pages become separated during grading. You will have three hours to complete this exam. Write all of your answers on the exam itself. If you need more space to answer a given problem, continue on the back of the page, but clearly indicate that you have done so. This exam is closed-book. You may use one sheet of notes. You may use a calculator. Do not do anything that might be perceived as cheating. The minimum penalty for cheating will be a grade of zero. Show all of your work on all problems. Correct answers that do not include work demonstrating how they were generated may not receive full credit, and answers that show no work cannot receive partial credit. The exam is meant to test your understanding. Ample time has been provided. So be patient and read the questions/problems carefully before you answer. Good luck! Question Points Score ISA 14 MP 15 Cache Cache and VM Pipelining 9 Total: 70

1. ISA (14 points) Branch predication is a computer architecture design strategy that allows each instruction to either perform an operation or do nothing based on a condition. The condition, called a predicate, is determined based on the value of a general purpose register. For example, the following instruction executes when R1 is positive and does nothing if R1 is non-positive. (R1) ADD R2, R3, 3 Answer the questions below. (a) (2 points) List one advantage and one disadvantage for implementing predication compared to using the traditional branch instruction. Any answer that makes sense is accepted. There are many advantages/disadvantages you can talk about. Example: Advantage: More compact code, more spacial locality for instructions Disadvantage: harder to implement, complex (b) (5 points) Rewrite the following simple program using predicates. The resulting program should not have any branch or jump instructions. Explain any optimizations that you make and feel free to overwrite registers R1 and R2 as long as the result is not affected. Note: Each instruction needs to have a predication register. Assume R3 is initially 0. 1 ; R0 = 0 R5 = 1 2 ; VALUE1 and VALUE2 3 ; are both non-zero 4 LDR R1, R0, VALUE1 5 BRp FOO 6 CONT: LDR R2, R0, VALUE2 7 BRn BAR 8 END: ADD R3, R3, 0 9 BRp GOOD 10 ADD R3, R0, 0xBADD 11 HALT 12 GOOD: ADD R3, R0, 0x600D 13 HALT 14 FOO: ADD R3, R0, 1 15 LEA R7, CONT JMP R7 17 BAR: AND R3, R0, 1 18 LEA R7, END 19 JMP R7 Page 2

Assuming R3 is 0 as initial condition 1 (R5) LDR R1,R0,VALUE1 2 (R1) ADD R3,R0,1 3 (R5) LDR R2,R0,VALUE2 4 (R5) RSHFL R2,R2,15 //get sign bit 5 (R2) AND R3,R0,1 //THIS LINE SETS R3 to ZERO 6 (R3) ADD R3,R0,0x600D 7 (R3) HALT 8 (R5) AND R3,R0,0xBAAD 9 (R5) HALT Page 3

(c) (2 points) What characteristics should VALUE1 and VALUE2 satisfy to make R3 end with value 0x600D/0xBADD? Since value1 and value2 are both non zero we get 0x600D when value1 and value2 both positive, 0xBAAD else. (d) (5 points) Given a system that is able to execute two parallel instructions (which do not have data dependencies on each other), rewrite the following code with predications implemented and explain how predication can help speed up the code. If you need additional registers in your code, you are free to use registers T1, T2, and T3. 1 ; Assume R0 has value 0, 2 ; R9 has value 1 3 LDR R2, R0, VALUE1 4 LDR R3, R0, VALUE2 5... 6 ; Some instructions that 7 ; compute the value to 8 ; put in location ANS 9 ; based on R2 and R3. 10... 11 LDR R1, R0, ANS 12 BRp SEG1 13 BRn SEG2 14 END:... 15 ; Wrapping up... 17 HALT 18 SEG1: ; Do multiply 19 MULT R4, R5, R6 20 STR R4, R0, ANS 21 LEA R7, END 22 JMP R7 23 SEG2: ; Do divide 24 DIV R8, R5, R6 25 STR R8, R0, ANS 26 LEA R7, END 27 JMP R7 Page 4

There are two main points for this problem. Predication elimates branch/jmp instructions to shorten code. Predication allows us to execute both SEG1 and SEG2 in parallel, each equiped with a different predication register. 1 /* opening stage is not important and is thus ignored */ 2 P0 P1 3 (R9) LDR R1,R0,ANS No-op 4 (R9) RSHFL T1,R1,15 No-op 5 (R1) MULT R4,R5,R6 (T1) DIV R8,R5,R6 6 (R1) STR R4,R0,ANS (T1) STR,R8,R0,ANS 7 (R9) HALT (R9) HALT Page 5

2. MP (15 points) (a) (6 points) A copy of the MP 1 datapath is attached at the end of this exam. Implement the new instruction Memory Increment by modifying the datapath. The instruction definition is: MEMINC BaseR, offset6 memword[basersext(offset6)<<1] memword[basersext(offset6)<<1] 1 In the table below, list all the components of the given datapath that you need to change and then give the specific change for each component. You should not add any new components, just modify the original components and add signals. For example, you cannot add a MUX, but you can expand an existing MUX to be of larger size. Only the table will be graded. No exceptions. Component ALUMUX Change Expand to take MDR output (mem_wdata) as input ALU Allow B 1 operation (b) (4 points) Complete the state machine below to implement the new instruction. Fr om Fetch Decod e Page 6

Page 7

(c) (3 points) For the given C code, complete the equivalent LC-3b assembly programs below. One uses the original LC-3b ISA and the other uses the ISA with the Memory Increment instruction included. Assume N is positive. 1 for (int i = 0; i < N; i) 2 vals[i]; Original ISA LOOP: LDR R1, R0, N LEA R2, VALS LDR R3, R2, 0 ADD R3, R3, 1 STR R3, R2, 0 ADD R2, R2, #2 ADD R1, R1, #-1 BRp LOOP END: BRnzp END N: DATA2 0x0040 VALS: DATA2 0x0002 DATA2 0x0021... ISA w/ Memory Increment instruction LOOP: LDR R1, R0, N LEA R2, VALS MEMINC R2, 0 ADD R2, R2, #2 ADD R1, R1, #-1 BRp LOOP END: BRnzp END N: DATA2 0x0040; Variable N VALS: DATA2 0x0002 DATA2 0x0021... ; Rest of Array Omitted Give an expression for the number of instructions saved in the new ISA s program as a function of N. 2N (d) (2 points) A student proposes putting a loop counter in memory and using the new memory increment instruction to increment the counter every iteration. What is a performance issue with this proposed method even if condition codes could be generated for memory locations? Memory Latency Page 8

3. Cache ( points) (a) A 2-way set associative write back cache with true LRU replacement policy requires 15 2 29 2 9 bits of storage to implement its tag store (including bits for valid, dirty, and LRU). The cache is virtually indexed and physically tagged. The virtual address space is 1 MB, the page size is 2 KB, and each cache block is 8 bytes. i. (2 points) What is the size of the data store in bytes? Ans. 8 KB. The cache is 2-way set associative. So each set has 2 tags each of size t 2 valid bits, 2 dirty bits and 1 LRU bit (because a single bit is enough to implement perfect LRU for 2-way set associative cache). Tag store size = 2 i (2 t 2 2 1) = 15 2 9 Therefore, 2t = 10 t = 5, i = 9 Data store size = 2 i (2 8) bytes = 2 9 (2 8) = 8 K B ii. (2 points) How many bits of the virtual index come from the virtual page number? Ans. 1 bit Page size is 2 KB. Hence the page offset is 11 bits (bits 10:0). The cache block offset os 3 bits (bits 2:0) and the virtual index is 9 bits (bits 11:3). Therefore, one bit of the virtual index (bit 11) comes from the virtual page number. iii. (2 points) What is the physical address space of this memory system? Ans. 64 KB The page offset is 11 bits. The physical frame number, which is the same as the physical tag is 5 bits. Therefore, the physical address space is 2 (115) = 2 bytes = 64 K B (b) (2 points) Lyle is dreaming of a multicore LC-3s processor with virtual memory support. The processor will have 10 KB pages, a block size of 256 bytes, and a shared L3 cache. Lyle wants to make the L3 cache as large as 128 MB, but is concerned about the synonym problem and thinks it will complicate the design. What solution would you suggest to Lyle to solve the synonym problem? Ans. L3 cache should have no synonym problem as it is physically addressed Page 9

(c) (8 points) Below are four different sequences of memory addresses generated by a program running on a processor with a cache. The cache hit ratio for each sequence is also shown. Sequence No. Address Sequence Hit Ratio 1 0, 512, 1024, 1536, 2048, 1536, 1024, 512, 0 0.33 2 0, 2, 4, 8,, 32 0.33 3 0, 512, 1024, 0, 1536, 0, 2048, 512 0.25 4 0, 64, 128, 256, 512, 256, 128, 64, 0 0.33 Assume that the cache is initially empty at the beginning of each sequence, all memory accesses are one byte accesses, all addresses are byte addresses. Find parameters below such that a cache with the discovered parameters would behave according to the above table. i. Associativity ii. Block size iii. Total cache size iv. Replacement policy (LRU, Pseudo LRU, or FIFO) i. Associativity Ans. 4 For sequence 1, blocks 0, 512, 1024 and 1536 are the only ones that are reused and could potentially result in cache hits when they are accessed the second time. Three of these four blocks should hit in the cache when accessed for the second time to give a hit rate of 0.33 3 i.e. 9. Given that the block size is 8 and for either cache size (256 B or 512 B), all of these blocks map to set 0. Hence, an associativity of 1 or 2 would cause at most one or two of these four blocks to be present in the cache when they are accessed for the second time, resulting in a maximum possible hit rate of less than 3 9. However the hit rate for this sequence is 3 9. Therefore an associativity of 4 is the only one that could potentially give a hit ratio of 0.33 or 3 9. ii. Block size Ans. 8 bytes For sequence 2, only 2 out of the 6 accesses (specifically those to addresses 2 and 4) can hit in the cache, as the hit ratio is 0.33. With any other cach blocks size but 8 bytes, the hit ratio is either smaller or larger than 0.33. Therefore the cache block size is 8 bytes. iii. Total cache size Ans. 256 B. For sequence 3, a total cache size of 512 B will give a hit rate of 4 9 with a 4-way associative Page 10

cache and 8 byte blocks regardless of the replacement policy which is higher than 0.33. Therefore the total cache size is 256 bytes. iv. Replacement policy (LRU, Pseudo LRU, or FIFO) Ans. LRU For the aformentioned cache parameters, all cache lines in sequence 4 map to set 0. If a FIFO replacement policy were used, the hit ratio would be 3 8, whereas if LRU replacement policy were used, the hit ratio would be 1 4. Therefore the replacement policy is LRU. Page 11

(d) (8 points (bonus)) You have three processors D, E, and F each with only one level of cache. The caches have the following parameters: All caches have a total size of 128 bytes a block size of 32 bytes LRU replacement policy D uses a direct mapped cache E uses a 2-way set associative cache F uses a fully associative cache A benchmark was run to evaluate the processors which tests memory read performance by issuing read requests to the cache. Assume the caches are empty at the beginning of the benchmark. The benchmark generates the following cache accesses: A B A H B G H H A E H D H G C C G C A B H D E C C B A D E F Each letter is a unique cache block and all eight cache blocks are contiguous in memory. However, the ordering of letters does not correspond to the cache block ordering in memory. i. The benchmark running on processor D generates the following sequence of cache misses: A B A H B G A E D H C G C B D A F Identify which cache blocks belong in the same set (for the cache in processor D). Ans. A and B C and G H and D E and F ii. For processor E, the benchmark crashes after the following sequence of cache misses: A B H G E Can you identify which cache blocks are in the same set for the cache of processor E? Explain your answer. Ans. If h was in the same set as A and B then the B right after H would have missed. Similarly if G was in the same set as A and B, the A right before E have missed. Using this information the sets are respectively, A, B, E, and F H, G, C, and D The simulation data of the cache up to the point it breaks is shown below. Req : LRU0: A B A H B G H H A E - A B B A A A A B A LRU1: - - - - - H G G G G Page 12

iii. Write down, in order of generation, the sequence of cache misses for the benchmark running on processor F. Ans. By simulating the cache and using the requests: Req : A B A H B G H H A E H D H G C C G C A B H D E C C B A D E F Miss: x x x x x x x x x x x x x x x x x x x LRU : - - - - - A A A B G G A A E D D D D H G C A B H H D E C B A iv. What is the cache miss rate for the benchmark running on processor F? Ans. 19 30 Page 13

4. Cache and VM ( points) Consider a memory system with the following parameters and components: Byte addressable 256 byte (2 8 byte) page size Cache: Virtually-indexed and physically-tagged 4-way set-associative with 6 4 index bits 4 KB (2 1 2 byte) 1 KB (2 1 0 byte) data storage (excluding bits for dirty, valid, tag and LRU) Read allocate policy Indexing the data array takes 10 ns Indexing the tag array takes 8 ns Tag comparison takes 4 ns Multiplexing the output data takes 3 ns A cache miss takes 100 ns to access the main memory and allocate to the cache line Assume a hit or miss is detected immediately after the tag comparison Initially empty (all lines are invalid) TLB: Fully-associative A TLB access takes 5 ns Read allocate policy TLB is updated on a TLB miss All entries are listed below Valid VPN PPN 0 00 0000 0001 0001 0000 1 00 0000 0010 0000 1110 0 00 0001 0110 0011 0011 0 00 0001 1011 0000 0000 1 11 1010 0100 1000 0100 1 11 0100 0101 0011 0011 1 10 0010 1010 1100 0110 0 00 0000 0000 0000 0001 Page Table: Single level page table A page table access takes 80 ns Some of the entries are listed below Valid VPN PPN 0 00 0000 0000 0001 0000 1 00 0000 0001 0011 0011 1 00 1101 0010 0000 0000 0 01 0000 0011 0010 0100 1 01 1010 0010 1110 0001 1 01 1111 1101 0000 1110 1 10 0000 0110 1100 0110 0 11 1111 1111 0101 0110 Page 14

(a) (12 points) Fill in the blanks and calculate the cache access times for the following actions in sequence (the second action follows immediately after the first one). Show your calculations for full credit. Write the address in hex and circle hit or miss. i. Read virtual address 4x00107 Cache access time: 207 ns Physical address: x3307 Cache hit / miss TLB hit / miss VA: 00 0000 0001 0000 0111 TLB miss on VPN = 00 0000 0001 PA: 0011 0011 0000 0111 Cache Compulsory Miss 5 80 5 = 90 ns to get the physical tag 4 ns to detect a cache miss by tag comparison 100 ns to access the main memory 10 3 = 13 ns to access data (tag access can be done in parallel) ii. Read virtual address 4x34500 Cache access time: 13 ns Physical address: x3300 Cache hit / miss TLB hit / miss VA: 11 0100 0101 0000 0000 TLB hit on VPN = 11 0100 0101 PA: 0011 0011 0000 0000 Cache hit Parallelism: Indexing tag tag comparison = 8 4 = 12 ns Indexing data multiplexing data = 10 3 = 13 ns (b) (2 points) Write a virtual address in hex that will cause a page fault. How will it be handled when this address is accessed? x000xx/x103xx/x3ffxx A page fault exception must be handled by OS to find missing page in secondary storage (disk). (c) (2 points) When should the TLB be flushed? Explain why. On context switch, so one program cannot access memory of a different program (security). Page 15

5. Pipelining (9 points) (a) (3 points) What is highest speedup possible through pipelining for a 6 instruction program if latch delay is 2 ns and total combinational logic delay of a non-pipelined design is 10 ns? The highest speedup can be obtained when dividing the total combinational logic into N stages, which each stage taking 10/N ns. On the non-pipelined processor, the program takes 6 10 = 60 ns to run. On a pipelined processor, each stage takes 10 N 2 ns. The program in total takes ( ) 10 (N 1 6) N 2 ( ) 10 = (N 5) N 2 ns The total time is minimized for N = 5. The speedup is 60 40 = 1.5. (b) (2 points) Give a specific example of a sequence of assembly instructions that include a data dependency (hazard) that cannot be resolved by forwarding alone. 1 LDR R1, R0, 0 2 ADD R0, R1, R1 (c) (4 points) Consider the code below. 1 add $t0, $s0, $s1 2 xor $t1, $t0, $s2 3 lw $s0, -12($a0) 4 sub $s5, $s0, $s1 Is it possible to resolve any of the hazards in the above code by reordering the instructions so that forwarding would be unnecessary? If yes, show how. If not, explain why not. It s possible to resolve one, but not both of the hazards in the above code by moving the xor after the sub. 1 add $t0, $s0, $s1 2 lw $s0, -12($a0) 3 sub $s5, $s0, $s1 4 xor $t1, $t0, $s2 Page

Appendix: MP 0 Datapath 2 pcmux_sel load_pc marmux_sel load_mar 0 1 PC 0 1 MAR mem_address mdrmux_sel load_mdr ADJ9 mem_rdata 0 1 MDR mem_wdata offset9 load_ir load_regfile storemux_sel 9 3 dest sr1_out alumux_sel aluop opcode 4 IR 3 3 sr1 sr2 1 ALU REG sr2_out 0 FILE 0 1 6 offset6 ADJ6 ir_nzp GENCC load_cc 3 3 CC CCCOMP branch_enable regfilemux_sel 0 1 Page 17

Appendix: LC-3b State Diagram Page 18

Appendix: LC-3b ISA ADD ADD AND AND BR JMP JSR JSRR LDB LDI LDR 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0001 DR SR1 0 00 SR2 0001 DR SR1 1 imm5 0101 0101 0000 1100 0100 0100 n DR SR1 0 00 SR2 DR SR1 1 imm5 z 000 p PCoffset9 BaseR 000000 1 PCoffset11 0 00 BaseR 000000 0010 DR BaseR offset6 1010 DR BaseR offset6 0110 DR BaseR offset6 LEA 1110 DR PCoffset9 NOT RET RTI 1001 1100 1000 DR SR 111111 000 111 000000 000000000000 SHF 1101 DR SR A D imm4 STB 0011 SR BaseR offset6 STI 1011 SR BaseR offset6 STR 0111 SR BaseR offset6 TRAP 1111 0000 trapvect8 Page 19