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

Similar documents
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. Chapter 5 The LC-3. Instruction Set Architecture

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

Computing Layers. Chapter 5 The LC-3

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

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

EEL 5722C Field-Programmable Gate Array Design

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

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

Instruction Set Architecture

COSC121: Computer Systems: Review

CS 2461: Computer Architecture I

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

COSC121: Computer Systems: Review

LC-3 Instruction Set Architecture

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

LC-3 Instruction Set Architecture. Textbook Chapter 5

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

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

UNIVERSITY OF WISCONSIN MADISON

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

appendix a The LC-3 ISA A.1 Overview

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

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

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

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

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

Memory Usage in Programs

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

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

System Calls. Chapter 9 TRAP Routines and Subroutines

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

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

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

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

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

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

Chapter 9 TRAP Routines and Subroutines

CS 135: Computer Architecture I

ECE 206, Fall 2001: Lab 3

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

Midterm 2 Review Chapters 4-16 LC-3

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

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

LC-2 Programmer s Reference and User Guide

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

Chapter 6 Programming the LC-3

C Functions and Pointers. C Pointers. CS270 - Fall Colorado State University. CS270 - Fall Colorado State University

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

Logistics. IIT CS 350 S '17 - Hale

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

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

Microprogrammed Control. ECE 238L μseq 2006 Page 1

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

Review Topics. Midterm Exam Review Slides

Review Topics. Midterm Exam Review Slides

Chapter 9 TRAP Routines and Subroutines

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

Chapter 4 The Von Neumann Model

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

Chapter 4 The Von Neumann Model

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

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

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

EE 3170 Microcontroller Applications

LC-3 Architecture. (Ch4 ish material)

Implementing Functions at the Machine Level

The Assembly Language of the Boz 5

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

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

Chapter 9 Computer Design Basics

Chapter 10 Computer Design Basics

CS 2461: Computer Architecture I

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

Major and Minor States

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Review Topics. parameter passing, memory model)

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

LC-3 Instruction Processing

Chapter 4 The Von Neumann Model

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

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

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

SISTEMI EMBEDDED. Computer Organization Central Processing Unit (CPU) Federico Baronti Last version:

SCRAM Introduction. Philipp Koehn. 19 February 2018

Transfer of Control. Lecture 10 JMP. JMP Formats. Jump Loop Homework 3 Outputting prompts Reading single characters

EE 308: Microcontrollers

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

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

ECE 375 Computer Organization and Assembly Language Programming Winter 2018 Solution Set #2

LC-3 TRAP Routines. Textbook Chapter 9

Computer Architecture, IFE CS and T&CS, 4 th sem. Single-Cycle Architecture

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?

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss

Computer Logic II CCE 2010

Transcription:

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ADD + 0001 1 0 00 2 Computer Science 210 s1c Computer Systems 1 2012 Semester 1 Lecture Notes ADD + AND + AND + BR JMP 0001 1 1 imm5 0101 1 0 00 2 0101 1 1 imm5 0000 n z p 1100 000 BaseR 000000 J 0100 1 PCoffset11 Lecture 12, 26Mar12: Ch. 5: The LC-3 JR LD + LDI + 0100 0010 1010 0 00 BaseR 000000 L + 0110 BaseR offset6 James Goodman! LEA + NOT + 1110 1001 111111 RET 1100 000 111 000000 RTI 1000 000000000000 ST 0011 STI 1011 STR 0111 BaseR offset6 TRAP 1111 0000 trapvect8 Credits: McGraw-Hill slides prepared by Gregory T. Byrd, North Carolina State University reserved 1101 2012.03.26 CS210 276 Data Movement Instructions PC-Relative Addressing Mode Load -- read data from memory to register! LD: PC-relative mode! L: base+offset mode! LDI: indirect mode Store -- write data from register to memory! ST: PC-relative mode! STR: base+offset mode! STI: indirect mode Load effective address -- compute address, save in register! LEA: immediate mode! does not access memory Want to specify address directly in the instruction! But an address is 16 bits, and so is an instruction!! After subtracting 4 bits for opcode and 3 bits for register, we have 9 bits available for address. Solution:! Use the 9 bits as a signed offset from the current PC. 9 bits: -256! offset! +255 Can form any address X, such that: PC 256! X! PC + 255 Remember that PC is incremented as part of the FETCH phase; This is done before the EVALUATE ADESS stage. [Why does this matter?] 26-Mar-12 CS210 279 26-Mar-12 CS210 281

LD (PC-Relative) ST (PC-Relative) 26-Mar-12 CS210 282 26-Mar-12 CS210 283 Indirect Addressing Mode LDI (Indirect) With PC-relative mode, can only address data within 256 words of the instruction.! What about the rest of memory? Solution #1:! Read address from memory location, then load/store to that address. First address is generated from PC and IR (just like PC-relative addressing), then content of that address is used as target for load/store. 26-Mar-12 CS210 284 26-Mar-12 CS210 285

STI (Indirect) Base + Offset Addressing Mode With PC-relative mode, can only address data within 256 words of the instruction.! What about the rest of memory? Solution #2:! Use a register to generate a full 16-bit address. 4 bits for opcode, 3 for src/dest register, 3 bits for base register -- remaining 6 bits are used as a signed offset.! Offset is sign-extended before adding to base register. 26-Mar-12 CS210 286 26-Mar-12 CS210 287 L (Base+Offset) STR (Base+Offset) 26-Mar-12 CS210 288 26-Mar-12 CS210 289

Load Effective Address LEA (Immediate) Computes address like PC-relative (PC plus signed offset) and stores the result into a register. Note: The address is stored in the register, not the contents of the memory location. 26-Mar-12 CS210 290 26-Mar-12 CS210 291 Example Control Instructions Address Instruction Comments x30f6 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 1 R1! PC 3 = x30f4 x30f7 0 0 0 1 0 1 0 0 0 1 1 0 1 1 1 0 R2! R1 + 14 = x3102 x30f8 0 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 M[PC - 5]! R2 M[x30F4]! x3102 x30f9 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2! 0 x30fa 0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 R2! R2 + 5 = 5 x30fb 0 1 1 1 0 1 0 0 0 1 0 0 1 1 1 0 x30fc 1 0 1 0 0 1 1 1 1 1 1 1 0 1 1 1 opcode M[R1+14]! R2 M[x3102]! 5 R3! M[M[x30F4]] R3! M[x3102] R3! 5 26-Mar-12 CS210 292 Used to alter the sequence of instructions (by changing the Program Counter) Conditional Branch! branch is taken if a specified condition is true signed offset is added to PC to yield new PC! else, the branch is not taken PC is not changed, points to the next sequential instruction Unconditional Branch (or Jump)! always changes the PC TRAP! changes PC to the address of an OS service routine! routine will return control to the next instruction (after TRAP) 26-Mar-12 CS210 294

Condition Codes Branch Instruction LC-3 has three condition code bits: N -- negative Z -- zero P -- positive (greater than zero) Set by any instruction that writes a value to a register (ADD, AND, NOT, LD, L, LDI, LEA) Branch specifies one or more condition codes. If the set bit is specified, the branch is taken.! PC-relative addressing: target address is made by adding signed offset (IR[8:0]) to current PC.! Note: PC has already been incremented by FETCH stage.! Note: Target must be within 256 words of BR instruction. Exactly one will be set at all times! Based on the last instruction that altered a register If the branch is not taken, the next sequential instruction is executed. 26-Mar-12 CS210 295 26-Mar-12 CS210 296