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

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

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

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

Instruction Set Architecture

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

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

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

LC-3 Instruction Processing

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

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

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

EEL 5722C Field-Programmable Gate Array Design

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

Computing Layers. Chapter 5 The LC-3

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

Memory Usage in Programs

Chapter 6 Programming the LC-3

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

COSC121: Computer Systems: Review

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

appendix a The LC-3 ISA A.1 Overview

LC-3 Instruction Set Architecture

COSC121: Computer Systems: Review

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

LC-3 Instruction Set Architecture. Textbook Chapter 5

UNIVERSITY OF WISCONSIN MADISON

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

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

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

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

10/30/2016. How Do We Write Instructions? ECE 120: Introduction to Computing. Put Bits into Memory, Then Execute the Bits

CS 2461: Computer Architecture I

CS 135: Computer Architecture I

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

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

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

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

2.2 THE MARIE Instruction Set Architecture

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

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

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

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

Midterm 2 Review Chapters 4-16 LC-3

UNIVERSITY OF WISCONSIN MADISON

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

Logistics. IIT CS 350 S '17 - Hale

sarm User Guide Note that a space must appear before the operation field because any word beginning in the first column is a label

LC-2 Programmer s Reference and User Guide

Chapter 4 The Von Neumann Model

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

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?

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

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

( input = α output = λ move = L )

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

Lab8: SAM Assembler and Simulator

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

ISA Instruction Operation

Wednesday, February 4, Chapter 4

Review Topics. Midterm Exam Review Slides

Birkbeck (University of London) Department of Computer Science and Information Systems. Introduction to Computer Systems (BUCI008H4)

Chapter 4 The Von Neumann Model

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

Chapter 7 Assembly Language

Module 5 - CPU Design

Review Topics. Midterm Exam Review Slides

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

Advanced Computer Architecture-CS501. Vincent P. Heuring&Harry F. Jordan Chapter 2 Computer Systems Design and Architecture

CS 270 Fall 2013 Mock Final

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

Computer Organization II CMSC 3833 Lecture 33

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

ECE 411, Exam 1. Good luck!

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

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

Outcomes. Lecture 13 - Introduction to the Central Processing Unit (CPU) Central Processing UNIT (CPU) or Processor

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

Faculty of Engineering Systems & Biomedical Dept. First Year Cairo University Sheet 6 Computer I

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

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

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

LC-3 Architecture. (Ch4 ish material)

The Assembly Language of the Boz 5

Wednesday, September 13, Chapter 4

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

SCRAM Introduction. Philipp Koehn. 19 February 2018

CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions

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

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

Computing Layers. Chapter 7 Assembly Language

LC-3 Assembly Language

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

ECE 206, Fall 2001: Lab 3

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

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

Programming Studio #4 ECE 190

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

Transcription:

ECE 109 Sections 602 to 605 Exam 2 Fall 2007 Solution 6 November, 2007 Problem 1 (15 points) Data Path In the table below, the columns correspond to two LC/3 instructions and the rows to the six phases of the LC/3 instruction cycle as described in the textbook. Within this table describe how the PC, MAR, MDR, and register files of the LC/3 datapath are used or modified in each instruction cycle phase for the two instructions. [The FETCH and DECODE rows only have one cell, since these two phases act similarly for all instructions.] It's most important to know how this internal registers are used and in what order that are accessed and modified rather than matching actions with specific phases. The detailed answer below comes from a careful reading of section 4.3.2 and particularly Example 4.4. The grading was complex. There are 10 actions performed in the instruction and there are 3 no-action cells. 1.5 points was given for identifying each of these. Incorrect statement were marked, but generally ignored in grading though points were sometimes deducted for serious errors. Of course, no answer received more than 15 points and no answer less than 0 points. FETCH DECODE EVALUATE ADDRESS FETCH OPERANDS EXECUTE STORE RESULT ADD R3, R4, #5 LDR R3, R4, #5 The PC is moved into the MAR (memory address register) while the PC is simultaneously incremented. The memory then reads a value (the next instruction) into the MDR (memory data register). No action on targeted registers on this phase. Skipped on ADD. R4 is added 5. R4 is obtained from the register file. The ALU adds R4 and 5. Skipped on LDR. The sum of R4 and 5 is sent to the MAR. The memory reads a data value into MDR. Result is stored in R3. Result is stored in R3. ECE 109 602-605 1 of 5 Exam 2

Problem 2 (15 points) Memories Using the symbol table shown below BASIE x3442 CARMICHAEL x3462 DORSEY x3482 ELLINGTON x34a2 write the appropriate 16-bit LC-3 machine language word, in binary or hex, for each assembly language statement shown in the left column. Assume that the instruction is located at address x3400 in all cases. If the assembly language statement is illegal, state the reason why this is so. Generally 0.5 points were taken off for each mistake. Many people did unnecessary translations from hexadecimal to decimal and back. For example, if the target address is x3462 and the PC is x3401, the offset is x61. Subtractions like that can be made directly in hexadecimal. The hexadecimal can then be translated into binary as 0 0110 0001 without conversion to decimal. One common, and time consuming, problem was inappropriately treating 61 as a decimal number and translating it into the binary number 111101. On the last problem, some people pointed out that the standard LC/3 does not support a trap with number x55. ADD R0,R2,#12 0001 000 010 1 01100 AND R7,R7,x12 18 (x12) too big for signed 5 bits AND R7,R7,R7 0101 111 111 000 111 BRnp DORSEY 0000 101 010000001 BRpz BASIE BRpz is not a valid opcode LD R3,CARMICHAEL 0010 011 001100001 LEA R2,ELLINGTON 1110 010 010100001 NOT R5,R6 1001 101 110 111111 STI R5,BASIE 1011 101 001000001 STR R3,R4,x14 0111 011 100 010100 TRAP x55 1111 0000 0101 0101 ECE 109 602-605 2 of 5 Exam 2

Problem 3 (15 points) The binary program shown in the left column below is loaded into memory at location x3000. In the right column, write the LC/3 assembly instructions or appropriate psuedo-ops corresponding to this program. Be sure to include appropriate labels and.orig and.end statements. Many people did not use labels and had answers like: LDI R4,x3007 for the second instruction. This is not a legal LC/3 instruction. Both of the following are correct LC/3 assembly language instructions: LDI R4,#5 LDI R4,x5 even though they are difficult to understand. By the way LDI R4,x3006 is even a bit more incorrect, as it doesn't take into account that the offset is added to the PC, which is one more than the address of the current instruction. Generally 0.5 points were deducted for each mistake. Binary Assembly.ORIG x3000 0101000000100000 AND R0,R0,#0 1010100000000101 LDI R4,Label07 0000011000000001 Label02 BRzp Label04 0001000000100001 ADD R0,R0,#1 0001100100000100 Label04 ADD R4,R4,R4 0000101111111100 BRnp Label02 1111000000100101 HALT 0100000000000000 Label07.FILL x4000.end ECE 109 602-605 3 of 5 Exam 2

Problem 4 (15 points) Assume that the eight LC/3 registers have the values shown on the left below and that the eight words of memory starting at memory location x3020 have the values shown on the right. Register Value Address Value R0 x0000 x3020 x0000 R1 x0001 x3021 x0001 R2 x0002 x3022 x0002 R3 x0003 x3023 x0003 R4 x0004 x3024 x0004 R5 x0005 x3025 x0005 R6 x4444 x3026 x6666 R7 x5555 x3027 x7777 For six of the following seven unanswered cases shown below, write either a single LC/3 instruction or a series of two LC/3 instructions to load the value stored in the specified memory location into register 5. Assume that each instruction is located at memory address x3010. Only three of the seven require the use of two instructions. Because I'm only grading six of the seven, you can miss one without penalty. In the difficult cases, you'll do well to give an explanation of your strategy. The point of this question was to test facility with LD, LDI, and LDR and knowledge of the restrictions imposed by the size of instruction bit fields. The question really should have prohibited.fill's, since they make it a bit too easy. (Also, that x3111 was supposed to be x3101.) 2.5 points, with liberal partial credit, were given to each correct answer for the best six of seven answers. x3021 LD R5,x10 LEA R5,xF0 x3111 LDR R5,R5,x10 x4424 x4444 x4464 x6666 x6667 x8888 LDR R5,R6,#-32 LDR R5,R6,#0 ADD R5,R6,x10 LDR R5,R5,x10 LDI R5,x15 LD R5,x15 LDR R5,R5,#1 ADD R5,R4,R4 LDR R5,R5,#0 ECE 109 602-605 4 of 5 Exam 2

Problem 5 (40 points) In this long question of many parts, write little (many only two or three instructions long) LC/3 programs to solve the following small problems. Answers that are unnecessary long or complicated will not receive full credit. 3 points Some people forgot set R3 to 0 before adding in five Write LC/3 code to set R3 to 5. AND R3,R3,#0 ADD R3,R3,#5 3 points 0.5 point deducted for unnecessary load from memory (.FILL) Write LC/3 code to turn off bits 3 to 0 of register R2. For example, if R2 contains x8ade, it should be set to x8ad0. In other words, and R2 with xfff0. AND R2,R2,xFFF0 5 points Many people needlessly changed R3 Write LC/3 code to set R5 from R3, according to the following formula: R5 = 3*R3 + 1 ADD R5,R3,R3 ADD R5,R5,R3 ADD R5,R5,#1 5 points Write LC/3 code to subtract R3 from R4. The result should be stored in R5. This is like computing the following equation: R5 = R4-R3 NOT R5,R3 ADD R5,R5,#1 ADD R5,R5,R4 8 points The solution below is certainly not the obvious one. The typical solution was ADD R4,R4,#0 BRn VNEG ADD R5,R4,#0 BR DONE VNEG AND R5,R5,#0 DONE grading 2 points for each BR, 1.0 points for test of R4, and 1.5 points for each update of R5 Write LC/3 code to compare R4 to zero and to (1) set R5 to R4, if R4 is positive, or (2) set R5 to 0, if R4 is negative. (This is similar to the IRS directive: Enter line 4 in line 5, if line 4 is a positive number. Otherwise, enter 0.) ADD R5,R4,#0 BRzp R5pos ; skip next if R4<0 AND R5,R5,#0 R5pos... ECE 109 602-605 5 of 5 Exam 2