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

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

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING 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

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

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

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

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

UNIVERSITY OF WISCONSIN MADISON

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

LC-3 Instruction Set Architecture. Textbook Chapter 5

LC-3 Instruction Set Architecture

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

CS 135: Computer Architecture I

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

Midterm 2 Review Chapters 4-16 LC-3

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

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

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

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

Memory Usage in Programs

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

CS 2461: Computer Architecture I

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

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

LC-2 Programmer s Reference and User Guide

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

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 411 Exam 1. This exam has 5 problems. Make sure you have a complete exam before you begin.

Instruction Set Architecture

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

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

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

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

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

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

Chapter 9 TRAP Routines and Subroutines

Chapter 9 TRAP Routines and Subroutines

Logistics. IIT CS 350 S '17 - Hale

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

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

Chapter 9 TRAP Routines and Subroutines

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

LC-3 TRAP Routines. Textbook Chapter 9

COSC121: Computer Systems: Review

System Calls. Chapter 9 TRAP Routines and Subroutines

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

EEL 5722C Field-Programmable Gate Array Design

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

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

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

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

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

ECE Homework 8

Chapter 6 Programming the LC-3

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

Computing Layers. Chapter 5 The LC-3

ECE 206, Fall 2001: Lab 3

Chapter 8 I/O. Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. But where does data in memory come from?

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

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

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

COSC121: Computer Systems: Review

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?

Lec-memMapIOtrapJSR SYS_BUS

LC-3 Input and Output

CS 2461: Computer Architecture I

LC-3 Input and Output

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

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

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

11/16/2016. Review Our Process for Programming. ECE 120: Introduction to Computing. A Typical Programming Process. Can a Computer Help Us Program?

I/O. University of Texas at Austin CS310H - Computer Organization Spring 2010 Don Fussell

Chapter 8 Input/Output

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

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

Routines and Subroutines

8.1 I/O Basics Device Registers. chapter

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

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

Chapter 7 Assembly Language

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

Programming Studio #4 ECE 190

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

Assembly Language. 7.1 Assembly Language Programming Moving Up o Level. chapter

11/6/2016. Let s Solve a Problem. ECE 120: Introduction to Computing. Overview of Our Task. Programs are Finite State Machines

Chapter 7 Assembly Language. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University

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

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

Assembly Language. University of Texas at Austin CS310H - Computer Organization Spring 2010 Don Fussell

Chapter 10 And, Finally... The Stack. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University

Transcription:

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON Instructor: Rahul Nayar TAs: Mohit Verma, Annie Lin Examination 4 In Class (50 minutes) Wednesday, May 3rd, 2017 Weight: 17.5% NO BOOK(S), NOTE(S), CALCULATORS OR ELECTRONIC DEVICES OF ANY SORT. The exam has eleven pages. You must turn in the pages 1-9. Circle your final answers. Plan your time carefully since some problems are longer than others. Use the blank sides of the exam for scratch work. LAST NAME: FIRST NAME: ID#: 1

Problem Maximum Points Points Earned 1 4 2 5 3 5 4 5 5 5 6 4 7 4 Total 32 2

1. The following LC-3 assembly code contains assembly syntax errors. Identify and fix at least 4 errors. (4 points).orig x3000 ADD R3, R3, ONE LD R5, STRING LOOP ADD R1, R1, #32 BRz LOOP MAIN LD R4, MAIN SUB R3, R3, #1 ST R3, STRING LOOP HALT ONE.FILL #1.BLKW 4.BLKW 3 STRING.STRINGZ "ABC".END.ORIG x3000 ADD R3, R3, ONE LD R5, STRING LOOP ADD R1, R1, #32 BRz LOOP MAIN LD R4, MAIN SUB R3, R3, #1 ST R3, STRING LOOP HALT ONE.FILL #1.BLKW 4.BLKW 3 STRING.STRINGZ "ABC".END 3

2. a) Fill in the symbol table for following LC-3 assembly code. You may not need to fill all rows. (5 points).orig x3000 AND R3, R3, #0 LD R4, VAL1 LOOP BRz EXIT JSR INC JSR DEC EXIT ST R3, ANS PUTS HALT INC ADD R3, R3, #1 RET DEC ADD R4, R4, #-1 RET ; Storage area for variables below: ANS.BLKW #5 VAL0.STRINGZ "252" VAL1.STRINGZ "CS".END SYMBOL LOOP EXIT INC DEC ANS VAL0 VAL1 Value (in hex) 0x3002 0x3005 0x3008 0x300A 0x300C 0x3011 0x3015 b) Convert the instruction stored at memory location 0x3006 into binary. 0xF022 (TRAP x22) 4

3. An LC-3 assembly code is given below: (5 points).orig x3000 AND R0, R0, #0 LD R0, DATA ADD R0, R0, #11 PRINT1 OUT AND R0, R0, #0 ADD R0, R7, R0 PRINT2 OUT HALT DATA.FILL 0xFFFF a. What is the output (in hex) after the OUT statement at the symbol PRINT1 finishes execution? 0x000A b. What is the output (in hex) after the OUT statement at the symbol PRINT2 finishes execution? Explain your answer. 0x3004 c. Complete the following incomplete code snippet that uses the memory-mapped LC-3 registers KBSR and KBDR to take input from the keyboard instead of the GETC instruction. Your code should store the value entered from keyboard in register R3. (Assume KBSR is mapped to address xfe00 and KBDR is mapped to address xfe02.) ECHO:,, KBSR, R3, KBDR KBSR KBDR.FILL xfe00.fill xfe02 ECHO: LDI, R0, KBSR BRnp ECHO LDI, R2, KBDR KBSR.FILL xfe00 KBDR.FILL xfe02 5

4. Short answer questions (5 points) a. Briefly describe what happens in the linking phase of an assembly program. Linking is resolving symbols between independent object files. b. How are the Display Data Register (DDR) and Display Status Register (DSR) used when TRAP x21 (OUT) is called? When the monitor is ready to display another character, DSR[15] is set to 1. DSR[7:0] is displayed and DSR[15] is set to 1. Any other data written to DDR is ignored while DSR[15] is zero. c. What is a service routine in LC-3? Give an example. A service routine is a function that performs a specific operation (optionally as part of the operating system). In LC-3, traps are service routines. Any trap will work here as an example. d. Briefly describe the difference between synchronous and asynchronous I/O. Synchronous I/O events occur at fixed, predictable rates. CPU reads every X seconds. Asynchronous I/O is unpredictable. Can use flag to achieve I/O. Example is keyboard input. 6

5. The following LC-3 assembly code implements a subroutine. After taking input, it outputs a lowercase letter (a-z) if the input was uppercase (A-Z), and a N otherwise. (5 points) SUBR GETC ADD R5, R0, 0 NOT R5, R5 ADD R5, R5, 1 LD R1, LBOUND LD R2, UBOUND ADD R3, R5, R2 BRn PNOT ADD R3, R5, R1 BRp PNOT LD R3, DIFF ADD R0, R0, R3 OUT BRnzp FINISH PNOT LD R0, N OUT FINISH RET UBOUND.FILL x5a ;ASCII value of "Z" LBOUND.FILL x41 ;ASCII value of "A" N.FILL x4e ;ASCII value of "N" DIFF.FILL x20 a. Is this code able to successfully return? Explain why or why not. No. R7 is overwritten by GETC and OUT. b. Add lines to the code above to make this subroutine callee-saved. You should not modify any existing lines. Clearly indicate which lines you have added and where. Before GETC: ST R0, SAVE0 ST R1, SAVE1 ST R2, SAVE2 7

ST R3, SAVE3 ST R5, SAVE5 ST R7, SAVE7 Before FINISH: LD R0, SAVE0 LD R1, SAVE1 LD R2, SAVE2 LD R3, SAVE3 LD R5, SAVE5 LD R7, SAVE7 After DIFF SAVE0.FILL x0 SAVE1.FILL x0 SAVE2.FILL x0 SAVE3.FILL x0 SAVE5.FILL x0 SAVE7.FILL x0 8

6. Examine the code below. You may assume that at the start of the program, all registers are set to 0. (4 points).orig x3000 GETC AND R3, R3, 0 ADD R3, R3, R0 LD R1, ONE NOT R1, R1 ADD R1, R1, 1 PRINT LD R0, C OUT LD R0, A OUT LD R0, T OUT ADD R0, R3, R1 BRz FINISH LD R0, S OUT FINISH HALT C.FILL x63 ; ASCII 'c' A.FILL x61 ; ASCII 'a' T.FILL x74 ; ASCII 't' S.FILL x73 ; ASCII 's' ONE.FILL x31 ; ASCII '1' a. If the input is the decimal number "3", what is output on the screen at the end of the program? cats b. OUT only prints out one character at a time. Instead of printing individually, we decide to replace the code stored at memory locations x3006 to x300b with the following, much shorter block of code: PRINT LD R0, C PUTS Will this output the same result as a)? Why or why not? You must explain your answer for credit. No. It'll output a bunch of garbage (whatever is stored at memory location x63 until it hits a null terminator). This is because PUTS uses the register value as an address, not as a value. 9

7. Multiple choice questions. Circle one answer for each question. (4 points) (i) Which of the following can not be used multiple times in a single assembly program? a).blkw b).fill c).orig d).stringz (ii) Assume that a LC-3 processor receives interrupts from 3 I/O devices (A, B and C) simultaneously. The priority levels for the interrupts are given below: A) PL0 B) PL7 C) PL6 Assuming that no other interrupts come in, which of the above interrupts is serviced last? a) A b) B c) C d) Any selected at random (iii) Our program begins at memory location x4000. We want to load the value x4020 into R3. Which LC-3 instruction can we use to accomplish this in a single line? a) LD b) LEA c) LDI d) ST (iv) Which register is used to store input data after IN is called? a) R7 b) R4 c) R1 d) R0 10

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. 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 11

Assembler Directives Trap Codes 12