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

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

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

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

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

ECE Homework 8

UNIVERSITY OF WISCONSIN MADISON

Midterm 2 Review Chapters 4-16 LC-3

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

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

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

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

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

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

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

Memory Usage in Programs

LC-3 TRAP Routines. Textbook Chapter 9

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

Chapter 6 Programming the LC-3

COSC121: Computer Systems: Review

Instruction Set Architecture

LC-3 Instruction Set Architecture. Textbook Chapter 5

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

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

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

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

LC-3 Instruction Set Architecture

CS 135: Computer Architecture I

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

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

EEL 5722C Field-Programmable Gate Array Design

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

ECE 206, Fall 2001: Lab 3

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

CS 2461: Computer Architecture I

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

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

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

COSC121: Computer Systems: Review

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

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

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

Routines and Subroutines

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

Computing Layers. Chapter 5 The LC-3

printf( Please enter another number: ); scanf( %d, &num2);

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

Chapter 9 TRAP Routines and Subroutines

UNIVERSITY OF WISCONSIN MADISON

LC-3 Input and Output

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

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

LC-3 Input and Output

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

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

Chapter 8 Input/Output

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

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

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

Chapter 9 TRAP Routines and Subroutines

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

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

Chapter 9 TRAP Routines and Subroutines

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

System Calls. Chapter 9 TRAP Routines and Subroutines

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

Lecture V Toy Hardware and Operating System

Programming Studio #4 ECE 190

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

LC-2 Programmer s Reference and User Guide

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

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

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

Textbook chapter 10. Abstract data structures are. In this section, we will talk about. The array The stack Arithmetic using a stack

Chapter 8 I/O. Computing Layers. I/O: Connecting to Outside World. I/O: Connecting to the Outside World

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

ECE/CS 252 Fall 2011 Homework 7 (25 points) // Due in Lecture on Nov. 30, 2011 (Wed)

Review Topics. Midterm Exam Review Slides

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

Logistics. IIT CS 350 S '17 - Hale

8.1 I/O Basics Device Registers. chapter

Review Topics. Midterm Exam Review Slides

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

HW2: MIPS ISA Profs. Daniel A. Menasce, Yutao Zhong, and Duane King Fall 2017 Department of Computer Science George Mason University

1/30/2018. Conventions Provide Implicit Information. ECE 220: Computer Systems & Programming. Arithmetic with Trees is Unambiguous

ECE198KL: Introduction to Computer Engineering II Spring 2013 due: 10 p.m. on Monday 21 January. Printing a Histogram

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

Ascii Art. CS 1301 Individual Homework 7 Ascii Art Due: Monday April 4 th, before 11:55pm Out of 100 points

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

10/27/2016. ECE 120: Introduction to Computing. The LC-3 Memory is Bit. Recall the Five Parts of the von Neumann Model

ECE251: Tuesday September 18

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

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

CS 135: Fall Project 2 Simple Cryptography

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

Transcription:

CIT 593: Intro to Computer Systems Homework #4: Assembly Language Due October 18, 2012, 4:30pm Instructions You may print this document and write your answers here, or submit solutions on a separate piece of paper. You should show your work, of course, but make sure your final answer is clearly indicated. Name Important note! Because we will discuss the solutions to this assignment during the exam review on October 18, this assignment may not be submitted late. Please be sure to submit it on time! Question #1 (5 points) You are writing an LC-3 program and, for the instruction at address x2024, you want to load the data held at address x6ab4 into register R1. However, you were sleeping in class when we talked about the load indirect (LDI) instruction so you only know about the other modes (LD, LDR, and LEA). So it seems to you that you'll need some combination of at least two instructions to accomplish this, since x6ab4 is too far from x2024 to use PC-relative mode. What sequence of instructions could you use instead, without using LDI? Question #2 (5 points) Consider the following LC-3 program written in assembly language. First, complete the table by writing the corresponding assembly language instructions. Address Encoding Instruction 0x3002 0001 0100 1010 0001 0x3003 0001 0100 1000 0010 0x3004 0001 0010 0111 1111 0x3005 0000 0011 1111 1101 In the program above, assume that R1 holds some positive integer n, and R2 holds the value 0. What value is held in R2 (in terms of n) when this program terminates? Assume the values manipulated by this program are small enough that overflow does not occur.

Question #3 (10 points) Consider the following LC-3 assembly language program:.orig x3000 LEA LEA LD R0, PHRASE R1, DATA R2, VALUE LOOP LDR R3, R0, #0 STR R3, R1, #0 ADD R0, R0, #1 ADD R1, R1, #1 ADD R2, R2, #-1 BRp LOOP END HALT PHRASE.STRINGZ "This is not a test!" DATA.BLKW x10 VALUE.FILL x10.end Create the symbol table entries generated by the assembler when translating the above program into machine code: Label LOOP END PHRASE DATA VALUE Offset What values are stored at the following addresses when this program is loaded into memory? Express the values in hexadecimal. Address x3001 Value x3008 X300A

Question #4 (10 points) Your friend is trying to write an assembly language program to read in two single-digit numbers from the input and print the sum to the output. However, his program is not working correctly: when he enters '5' and then '2', he expects '7' but the output is the letter d. He knows that you are an expert at assembly language programming and asks for your help. What is wrong with the program below? Hint: there are at least two errors in the code; you only need to identify and explain how to correct two of them. You don't have to actually write the correct code, just explain how to fix it. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26.ORIG x3000 JSR GET ; call subroutine JSR GET ; call subroutine again ADD R2, R0, R0 ; put the sum in R2 PRINT LDI R1, DSR ; write out to screen BRzp PRINT STI R2, DDR HALT ;; subroutine to read from the keyboard GET LDI R1, KBSR BRzp GET LDI R0, KBDR RET KBSR.FILL xfe00 KBDR.FILL xfe02 DSR.FILL xfe04 DDR.FILL xfe06.end

Question #5 (20 40 points) In this part, you will write an LC-3 assembly language program that allows the user to draw lines of color on the screen. Do not submit your code on paper! You will submit it using the turnin program, as in Homework #3; instructions will be posted on Piazza. Be sure that your program runs correctly in the LC-3 simulator before submitting it, of course! The program works as follows: first, the user enters either the 'r', 'g', or 'b' key, indicating that they want a red, green, or blue line to be drawn then, the user enters a number from 1 to 9, indicating the number of lines to draw the program draws the appropriate number of lines in the appropriate color, and then waits for the next input. The lines should be drawn starting at the top of the screen, and subsequent key presses should result in lines being drawn lower down the screen. For instance, if the user presses 'r', then '2', then 'g', then '4', the screen should show two red lines on top, with four green lines underneath. Other things to consider: When you re testing your program, be sure to click the white box below the black video output screen in the simulator; that box is for keyboard input and needs to have focus in the simulator. If the user presses the letter 'q' for the color, the program should terminate; you should ignore any other keys for the color, and instead continue to wait for a legal color input. The program only needs to handle lower-case letters for the color, i.e. you don't have to worry about R, G, etc. You can assume that the user will correctly enter a number from 1 to 9 when you're waiting for the number of lines to enter; you don't have to worry about error handling there. At some point, you will run out of lines on the screen. That's okay, you don't have to explicitly handle that condition. You may find it necessary (hint, hint) to hardcode some of the useful values and put them into memory locations in your program. Here are the ASCII values for the letters you need to check for: letter ASCII value r g b x72 x67 x62 q x71 Note that the ASCII value for the '1' key is not 1!! It's x31. The '2' key is x32, and so on. Here are the color codes that you need to use: color code red green blue x7c00 x03e0 x001f

Remember, to draw on the screen in the simulator, write the color code to the appropriate memory address, starting at xc000 (which is the upper lefthand corner). Each row on the screen has 128 pixels and thus is represented by 128 contiguous memory addresses. Go through Lab #3 again if you need a refresher. Advice on how to approach this assignment This is a challenging assignment so give yourself lots of time and think of it in small pieces. First, you need to somehow figure out which key the user entered. Start with the keyboard echo sample program in the textbook on page 207 (section 8.3.4) to make sure that you can read keyboard entry and that the program knows which keys were pressed. Next, modify the program so that you are able to determine whether the first key pressed was the letter 'r'. For testing purposes, just use 'r' for now, and don't worry about reading the second key press (in which the user enters the number of lines to draw) or any other characters just yet. Once your program has determined that the letter 'r' was pressed, use your solution from Lab #3 Exercise #1 (there is a solution on the course website, too) to draw a single red line across the screen. Be careful about which registers are holding which values! Then, after you've drawn a single red line across the street, branch back up to the start of the program and wait for the next keyboard input. Okay, now you're getting somewhere! Now you can draw a single red line each time the letter 'r' is pressed! From here, change the program so that it checks if the key is 'r', 'b', or 'g', and chooses a different color to draw depending on the letter that was entered. At this point, the program should be able to draw a red, blue, or green line each time one of those is pressed. Now you just have three more modifications to make: the program should quit if the user enters 'q' the program should continue to wait for legal input if the letter is not 'r', 'b', 'g', or 'q' after getting the color from the user, the program should read in the number of lines to draw, and then actually draw that number of lines You do not have to use subroutines in this assignment, but you can if it helps you organize everything. The hardest part of this assignment is that you will have lots of loops and need to keep track of which counters are in which registers. So use comments!