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

Similar documents
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

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

UNIVERSITY OF WISCONSIN MADISON

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

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/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

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

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: Mohit Verma, Annie Lin

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

appendix a The LC-3 ISA A.1 Overview

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

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

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

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

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

LC-3 Instruction Set Architecture

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

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

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

Memory Usage in Programs

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

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

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

UNIVERSITY OF WISCONSIN MADISON

CS 135: Computer Architecture I

LC-3 Instruction Set Architecture. Textbook Chapter 5

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

CS 2461: Computer Architecture I

LC-3. 3 bits for condition codes (more later) Fixed-length instructions, with 4-bit opcodes. IIT CS 350 S 18- Hale

Lab 1. Warm-up : discovering the target machine, LC-3

LC-2 Programmer s Reference and User Guide

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

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

Logistics. IIT CS 350 S '17 - Hale

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

EEL 5722C Field-Programmable Gate Array Design

Chapter 6 Programming the LC-3

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

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

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

Midterm 2 Review Chapters 4-16 LC-3

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

Computing Layers. Chapter 5 The LC-3

Review Topics. Midterm Exam Review Slides

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

Review Topics. Midterm Exam Review Slides

Instruction Set Architecture

Fill in your name, section, and username. DO NOT OPEN THIS TEST UNTIL YOU ARE TOLD TO DO SO.

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Review Topics

LC-3 Subroutines and Traps. (Textbook Chapter 9)"

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

COSC121: Computer Systems: Review

Subroutines & Traps. Announcements. New due date for assignment 2 5pm Wednesday, 5May

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

COSC121: Computer Systems: Review

Chapter 9 TRAP Routines and Subroutines

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

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

CIT 593: Intro to Computer Systems Homework #4: Assembly Language Due October 18, 2012, 4:30pm. Name

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

System Calls. Chapter 9 TRAP Routines and Subroutines

Chapter 9 TRAP Routines and Subroutines

ECE 206, Fall 2001: Lab 3

Chapter 9 TRAP Routines and Subroutines

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

1/17/2018. Task: Print a Number in Binary. ECE 220: Computer Systems & Programming. First Step: Break the Task into a Sequence of Two

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

11/10/2016. Review the Problem to Be Solved. ECE 120: Introduction to Computing. What Shall We Keep in the Registers? Where Are the Pieces in Memory?

TRAPs and Subroutines. University of Texas at Austin CS310H - Computer Organization Spring 2010 Don Fussell

컴퓨터개념및실습. 기말고사 review

Microprogrammed Control. ECE 238L μseq 2006 Page 1

LC-3 TRAP Routines. Textbook Chapter 9

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

UNIVERSITY OF WISCONSIN MADISON

ISA Instruction Operation

Implementing Functions at the Machine Level

Introduction to Computer Engineering. CS/ECE 252 Prof. Mark D. Hill Computer Sciences Department University of Wisconsin Madison

Major and Minor States

Fortunately not. In LC-3, there are a variety of addressing modes that deal with these concerns.

CS 2461: Computer Architecture I

The Assembly Language of the Boz 5

Homework 06. Push Z Push Y Pop Y Push X Pop X Push W Push V Pop V Push U Pop U Pop W Pop Z Push T Push S

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

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

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

ECE Homework 8

Lecture 20: AVR Programming, Continued. AVR Program Visible State (ones we care about for now)

LC-3 Instruction Processing

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

Review Topics. Final Exam Review Slides

Our Simulation Equivalent: -- readmemb( "os.bin" ) -- PC <== x0200

Programming Studio #4 ECE 190

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

Input & Output. Lecture 16. James Goodman (revised by Robert Sheehan) Computer Science 210 s1c Computer Systems 1 Lecture Notes

Implement useq's FSM's --- Next-state function --- Output function. We know: Any function can be implemented in AND-OR

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

Transcription:

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING COMPUTER SCIENCES DEPARTMENT UNIVERSITY OF WISCONSIN-MADISON Prof. Mark D. Hill & Prof. Mikko H. Lipasti TAs Sanghamitra Roy, Eric Hill, Samuel Javner, Natalie Enright Jerger, & Guoliang Jin Midterm Examination 3 In Class (50 minutes) Friday, November 16, 2007 Weight: 15% CLOSED BOOK, NOTE, CALCULATOR, PHONE, & COMPUTER. The exam in two-sided and has TEN pages, including two blank pages and a copy of the LC-3 Instruction Set handout on the final page (please feel free to detach this final page, but insert it into your exam when you turn it in). Plan your time carefully, since some problems are longer than others. NAME: SECTION: ID# 1

Problem Number Maximum Points Graded By 1 4 NEJ 2 4 NEJ 3 6 SJ 4 4 EH 5 4 SR 6 4 GJ 7 4 EH Total 30 2

Problem 1 (4 points) The following LC-3 instruction is located at memory address x5000. x5000: 0000 101 000000100 R0 contains 4 R1 contains 3 R2 contains 0 R3 contains 5 a. If the preceding instruction is the one shown below, what is the value of the PC after the instruction at 0x5000 is executed? x4fff: 0001 000 001 1 00001 x5000: 0000 101 000000100 0x5005 b. If the preceding instruction is the one shown below, what is the value of the PC after the instruction at 0x5000 is executed? x4fff: 0101 010 011 1 00000 x5000: 0000 101 000000100 0x5001 Problem 2 (4 points) Imagine the DR and BaseR fields of the LDR instruction are each 4 bits wide If the instruction is 0110 0001 0010 xxxx R0 R1 R2 R3 R4 x0 x0 x0108 xff x123 a. What is the maximum and minimum address that the above instruction could load from? 0x0100 to 0x010F b. What is the maximum number of registers for DR? 16 3

Problem 3 (6 points) The program below checks to see if the value stored in R0 is greater than or equal to the value stored in R1. If R0 is smaller than R1, the value of R1 is copied to R0. Otherwise nothing is done. Insert the missing LC-3 machine language instructions. Adding comments to each machine language instruction will assist in awarding partial credit. Address ISA Instruction x3000 1001 0100 0111 1111 ; NOT R2, R1 x3001 0001 0100 1010 0001 ; ADD R2, R2, #1 x3002 0001 0110 0000 0010 ; ADD R3, R0, R2 x3003 0000 0110 0000 0001 ; BRzp x3005 x3004 0001 0000 0110 0000 ; ADD R0, R1, #0 x3005 1111 0000 0010 0101 ; HLT Problem 4 (4 points) There is something wrong with the following code sequence. This code is supposed to continuously decrement the value stored in R5 until it is equal to zero, and then exit. Explain what happens when we try to execute this code. Comments are provided to save you the effort of decoding the machine language. Address ISA Instruction x3000 0001 1011 0111 1111 ; ADD R5, R5, #-1 x3001 0000 0111 1111 1110 ; BRzp x3000 x3002 1111 0000 0010 0101 ; HLT Explanation of what is wrong: Because the instruction at location x3001 branches on the zero condition code, the loop will have an extra iteration. 4

Problem 5 (4 points) a. Briefly describe 2 ways to partially execute a program while debugging it. (Any 2 of 3) Single Step: execute 1 instruction at a time Breakpoint: tell simulator/program to stop executing when it reaches a specific instruction Watchpoint: tell simulator/program to stop executing when the value in specific register or memory location changes b. Briefly describe the 3 ways to decompose a program into subtasks Sequential: do subtask 1 followed by subtask 2 Conditional: if condition is true, do subtask 1. If condition is false, do subtask 2 Iterative: repeat subtask over and over until test condition is false 5

P r o b l e m 6 ( 4 p o i n t s ) We are about to execute the following program: Address ISA Instruction x3000 0010 0000 0000 0101 ; LD R0, x005 X3001 0110 0000 0000 0000 ; LDR R0, R0, x0 x3002 0010 0010 1111 0000 ; LD R1, x0f0 x3003 0110 0100 0000 1110 ; LDR R2, R0, x0e x3004 1111 0000 0010 0101 ; HALT The state of the machine before the program starts is given below: Memory Address x3006 xabcd x2fff x122e xabdb x30f3 x200e x2257 x300e x3005 Memory Contents xabcd x1220 x4567 x9876 x0001 x0020 x3258 x0000 x92fe x3010 What will be the final contents of registers R0-R3 when we reach the HALT instruction? Write your answers in hexadecimal format. Register Initial contents Final contents R0 x200e 0x1220 R1 x200e 0x0020 R2 x3001 0x9876 R3 x3001 0x3001 6

Problem 7 (4 points) Answer: a a. If the value stored in R0 is 1 at the end of the execution of the following instructions, what can be inferred about R5? Address Instruction 0x3000 0101 000 000 1 00000 ; R0 R0 AND #0 0x3001 0101 100 101 1 000001 ; R4 R5 AND #1 0x3002 0000 010 000000001 ; BRz, #1 0x3003 0001 000 000 1 00001 ; R0 R0 + #1 a. R5 is odd b. R5 is even c. R5 is equal to 0 d. R5 is equal to 1 b. Which of the following LC-3 instructions at address 0x0200 will always clear register R5 (i.e. set the contents of R5 to all zeroes)? a. 0001 101 101 100000 b. 0101 101 101 100000 c. 1110 101 000 000000 d. 0010 101 000 000000 Answer: b 7

Scratch Sheet 1 (in case you need additional space for some of your answers) 8

Scratch Sheet 2 (in case you need additional space for some of your answers) 9

LC-3 Instruction Set (Entered by Mark D. Hill on 03/14/2007; last update 03/15/2007) PC : incremented PC. setcc(): set condition codes N, Z, and P. mem[a]:memory contents at address A. SEXT(immediate): sign-extend immediate to 16 bits. ZEXT(immediate): zero-extend immediate to 16 bits. Page 2 has an ASCII character table. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ADD DR, SR1, SR2 ; Addition 0 0 0 1 DR SR1 0 0 0 SR2 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR SR1 + SR2 also setcc() +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ADD DR, SR1, imm5 ; Addition with Immediate 0 0 0 1 DR SR1 1 imm5 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR SR1 + SEXT(imm5) also setcc() +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ AND DR, SR1, SR2 ; Bit-wise AND 0 1 0 1 DR SR1 0 0 0 SR2 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR SR1 AND SR2 also setcc() +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ AND DR, SR1, imm5 ; Bit-wise AND with Immediate 0 1 0 1 DR SR1 1 imm5 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR SR1 AND SEXT(imm5) also setcc() +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ BRx, label (where x = {n,z,p,zp,np,nz,nzp}) ; Branch 0 0 0 0 n z p PCoffset9 GO ((n and N) OR (z AND Z) OR (p AND P)) +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ if (GO is true) then PC PC + SEXT(PCoffset9) +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ JMP BaseR ; Jump 1 1 0 0 0 0 0 BaseR 0 0 0 0 0 0 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ PC BaseR +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ JSR label ; Jump to Subroutine 0 1 0 0 1 PCoffset11 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ R7 PC, PC PC + SEXT(PCoffset11) +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ JSRR BaseR ; Jump to Subroutine in Register 0 1 0 0 0 0 0 BaseR 0 0 0 0 0 0 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ temp PC, PC BaseR, R7 temp +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ LD DR, label ; Load PC-Relative 0 0 1 0 DR PCoffset9 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR mem[pc + SEXT(PCoffset9)] also setcc() +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ LDI DR, label ; Load Indirect 1 0 1 0 DR PCoffset9 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR mem[mem[pc + SEXT(PCoffset9)]] also setcc() +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ LDR DR, BaseR, offset6 ; Load Base+Offset 0 1 1 0 DR BaseR offset6 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR mem[baser + SEXT(offset6)] also setcc() +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ LEA, DR, label ; Load Effective Address 1 1 1 0 DR PCoffset9 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR PC + SEXT(PCoffset9) also setcc() +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ NOT DR, SR ; Bit-wise Complement 1 0 0 1 DR SR 1 1 1 1 1 1 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ DR NOT(SR) also setcc() +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ RET ; Return from Subroutine 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ PC R7 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ RTI ; Return from Interrupt 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ See textbook (2 nd Ed. page 537). +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ST SR, label ; Store PC-Relative 0 0 1 1 SR PCoffset9 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ mem[pc + SEXT(PCoffset9)] SR +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ STI, SR, label ; Store Indirect 1 0 1 1 SR PCoffset9 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ mem[mem[pc + SEXT(PCoffset9)]] SR +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ STR SR, BaseR, offset6 ; Store Base+Offset 0 1 1 1 SR BaseR offset6 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ mem[baser + SEXT(offset6)] SR +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ TRAP ; System Call 1 1 1 1 0 0 0 0 trapvect8 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ R7 PC, PC mem[zext(trapvect8)] +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ ; Unused Opcode 1 1 0 1 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ Initiate illegal opcode exception 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 10