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

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

Chapter 9 TRAP Routines and Subroutines

System Calls. Chapter 9 TRAP Routines and Subroutines

Chapter 9 TRAP Routines and Subroutines

Midterm 2 Review Chapters 4-16 LC-3

Implementing Functions at the Machine Level

appendix a The LC-3 ISA A.1 Overview

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

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

Chapter 9 TRAP Routines and Subroutines

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

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

LC-3 Instruction Set Architecture. Textbook Chapter 5

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

LC-3 TRAP Routines. Textbook Chapter 9

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

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

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

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

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

ECE 206, Fall 2001: Lab 3

Instruction Set Architecture

And. Fin a l l i... The Slack

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

LC-3 Instruction Set Architecture

Chapter 6 Programming the LC-3

Memory Usage in Programs

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

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

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

EEL 5722C Field-Programmable Gate Array Design

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

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

Chapter 10 And, Finally... The Stack

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?

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

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

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

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

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

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

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

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

Computing Layers. Chapter 5 The LC-3

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

CS 135: Computer Architecture I

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

COSC121: Computer Systems: Review

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

CS 2461: Computer Architecture I

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

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

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

COSC121: Computer Systems: Review

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

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

UNIVERSITY OF WISCONSIN MADISON

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

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

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

The Assembly Language of the Boz 5

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

Routines and Subroutines

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

CODE GENERATION Monday, May 31, 2010

Chapter 04: Instruction Sets and the Processor organizations. Lesson 18: Stack-based processor Organisation

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

Virtual Machine Tutorial

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

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

Binghamton University. CS-120 Summer Stacking Up. Text: Introduction to Computer Systems : Chapter 10

Chapter 7 Assembly Language

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

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

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

Intel 8086: Instruction Set

TYPES OF INTERRUPTS: -

The von Neumann Architecture. IT 3123 Hardware and Software Concepts. The Instruction Cycle. Registers. LMC Executes a Store.

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

! What do we care about? n Fast program execution. n Efficient memory usage. n Avoid memory fragmentation. n Maintain data locality

Chapter 10 Memory Model for Program Execution. Problem

Computing Layers. Chapter 7 Assembly Language

appendix b From LC-3 to x86

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

Lecture V Toy Hardware and Operating System

LC-3 Instruction Processing

ECE 411, Exam 1. Good luck!

ECE251: Tuesday September 18

2/6/2018. Let s Act Like Compilers! ECE 220: Computer Systems & Programming. Decompose Finding Absolute Value

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

Programming Model 2 A. Introduction

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

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

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

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

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

COSC 6385 Computer Architecture. Instruction Set Architectures

Transcription:

Homework 06 1. How many TRAP service routines can be implemented in the LC-3? Why? Since the trap vector is 8 bits wide, 256 trap routines can be implemented in the LC-3. Why must a instruction be used to return from a TRAP routine? Why won't a BRnzp (unconditional BR) instruction work instead? After the TRAP routine is executed, program control must be passed back to the code that called the TRAP instruction. This is done by copying the value in R7 into the PC. The instruction provides this functionality. BRnzp does not restore the PC. How many accesses to memory are made during the processing of a TRAP instruction? Twice.(Memory -> IR, Memory->PC) 2. What are the defining characteristics of a stack? Give two implementations of a stack and describe their differences. The defining characteristic of a stack is the unique specification of how it is to be accessed. Stack is a LIFO (Last in First Out) structure. This means that the last thing that is put in the stack will be the first one to get out from the stack. (Any two reasonable implementations are OK.) We can implement a stack by a sequence or a list. The difference between is how their elements store in memory. The fisrt one is sequential, while the other is discrete. 3. The input stream of a stack is a list of all the elements we pushed onto the stack, in the order that we pushed them. The output stream is a list of all the elements that are popped off the stack in the order that they are popped off. a. If the input stream is ZYXWVUTSR, create a sequence of pushes and pops such that the output stream is YXVUWZSRT. 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

Pop S Push R Pop R Pop T b. If the input stream is ZYXW, how many different output streams can be created. 14 different output streams. 4. Rewrite the PUSH and POP routines such that the stack on which they operate holds elements that take up two memory locations each. Assume we are writing a program to simulate a stack machine that manipulates 32-bit integers with the LC-3. We would need PUSH and POP routines that operate with a stack that holds elements which take up two memory locations each. Rewrite the PUSH and POP routines for this to be possible. This routine pushes the values in R0 and R1 onto the stack. R5 is set to 0 if operation is successful. If overflow occurs R5 is set to 1. This routine works with a stack consisting of memory locations x3fff(base) to x3ffa(max). PUSH ST R2, SaveR2 LD R2, MAX NOT R2, R2 ADD R2, R2, #1 ; R2 = -addr of stackmax ADD R2, R6, R2 BRz Failure STR R0, R6, #-1 STR R1, R6, #-2 ADD R6, R6, #-2 AND R5, R5, #0 LD R2, SaveR2 Failure AND R5, R5, #0 ADD R5, R5, #1 LD R2, SaveR2 MAX.FILL x3ffa SaveR2.FILL x0000 This routine pops the top two elements of the stack into R0 and R1. R5 is set to 0 if the operation is successful. If underflow occurs R5 is set to 1. This routine works with a stack consisting of memory locations x3fff(base) to x3ffa(max). POP ST R2, SaveR2 LD R2, EMPTY ; EMPTY <-- -x3fff ADD R2, R6, R2 BRzp Failure ; Underflow LDR R1, R6, #0 ; Pop the first value LDR R0, R6, #1 ; Pop the second value

ADD R6, R6, #2 AND R5, R5, #0 Failure AND R5, R5, #0 ADD R5, R5, #1 EMPTY.FILL x3fff SaveR2.FILL x0000 5.Figure out what the following program does..orig X3000 LEA R2, C ; R2=&C LDR R1, R2, #0 ;R1=x25 LDI R6, C ;R6=[x25] LDR R5, R1, #-3 ;R5=[x22] ST R5, C ;C=[x22] LDR R5, R1, #-4 ;R5=[x21] LDR R0, R2, #1 ;R0=&C+1 JSRR R5 ; ;trap x21,output E AND R3, R3, #0 ;R3=0 ADD R3, R3, #7 ;R3=7 LEA R4, B ;R4=&B A STR R4, R1, #0 ;[x25]=&b, [x26]=&b+2, [x27]=&b+4, [x28]=&b+6, ;[x29]=&b+8, [x2a]=&b+10,[x2b]=&b+12 ADD R4, R4, #2 ;R4=R4+2 ADD R1, R1, #1 ; ADD R3, R3, #-1 BRP A HALT B ADD R2, R2, #1 ;R2=&C+1 ; LDR R0, R2, #0 ;R0=[&C1+1] JSRR R5 ;trap x21, OUTPUT E TRAP X29 ; PC=B+8 ADD R2, R2, #15 ; ADD R0, R2, #3 LD R5, C ;R5=x25 TRAP X2B ;PC=&B+12 ADD R2, R2, #5 ;R2=&C+6 LDR R0, R2, #0 ;R0=[&C+6] JSRR R5 ;trap x21, OUTPUT TRAP X27 ;PC=[&B+6] JSRR R5 ;PC=&B ;.. JSRR R6 C.FILL X25

.STRINGZ "EE306 and tests are awesome".end Output EE some (You could refer to annotation I appended above) 6. Jane Computer (Bob's adoring wife), not to be outdone by her husband, decided to rewrite the TRAP x22 handler at a different place in memory. Consider her implementation below. If a user writes a program that uses this TRAP handler to output an array of characters, how many times is the ADD instruction at the location with label A executed? Assume that the user only calls this "new" TRAP x22 once. What is wrong with this TRAP handler? Now add the necessary instructions so the TRAP handler executes properly. Hint: uses R7 as linkage back to the caller ( is equivalent to JMP R7). ; TRAP handler ; Outputs ASCII characters stored in consecutive memory locations. ; R0 points to the first ASCII character before the new TRAP x22 is called. ; The null character (x00) provides a sentinel that terminates the output sequence. The execution time of ADD instruction at the location with label A is equal to the length of the array..orig x020f START ST R1, SAVER1 LDR R1, R0, #0 BRz DONE ST R0, SAVER0 AND R0, R0, #0 ADD R0, R1, #0 ST R7, SAVER7 TRAP x21 LD R0, SAVER0 LD R1, SAVER1 LD R7, SAVER7 A ADD R0, R0, #1 BRnzp START DONE SAVER0.BLKW #1 SAVER1.BLKW #1 SAVER7.BLKW #1.END

7. A zero-address machine is a stack-based machine where all operations are done by using values stored on the operand stack. For this problem, you may assume that the ISA allows the following operations: PUSH M - pushes the value stored at memory location M onto the operand stack. POP M - pops the operand stack and stores the value into memory location M. OP - Pops two values off the operand stack and performs the binary operation OP on the two values. The result is pushed back onto the operand stack. Note: OP can be ADD, SUB, MUL, or DIV for parts a and b of this problem. a. Draw a picture of the stack after each of the instructions below are executed. What is the minimum number of memory locations that have to be used on the stack for the purposes of this program? Also write an arithmetic equation expressing u in terms of v, w, x, y, and z. The values u, v, w, x, y, and z are stored in memory locations U, V, W, X, Y, and Z. PUSH V PUSH W PUSH X PUSH Y MUL ADD PUSH Z SUB DIV POP U Y x X X*y z w w W W X*y+w X*y+w z-( X*y+w) v v v v V v v v (z-(x*y+w))/v The minimum number of memory location is 4. U=(z-(x*y+w))/v b. Write the assembly language code for a zero-address machine (using the same type of instructions from part a) for calculating the expression below. The values a, b, c, d, and e are stored in memory locations A, B, C, D, and E. e = ((a * ((b - c) + d))/(a + c)) PUSH A PUSH C

ADD PUSH C PUSH B SUB PUSH D ADD PUSH A MUL DIV POP E