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

Similar documents
Instruction Set Architecture

COSC121: Computer Systems: Review

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

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

EEL 5722C Field-Programmable Gate Array Design

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

Chapter 4 The Von Neumann Model

Computing Layers. Chapter 5 The LC-3

COSC121: Computer Systems: Review

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

LC-3 Instruction Processing

Chapter 4 The Von Neumann Model

Chapter 4 The Von Neumann Model

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

CS 2461: Computer Architecture I

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

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

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

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

LC-3 Instruction Set Architecture. Textbook Chapter 5

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

LC-3 Instruction Set Architecture

LC-3 Architecture. (Ch4 ish material)

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

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

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

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

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

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

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

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

appendix a The LC-3 ISA A.1 Overview

UNIVERSITY OF WISCONSIN MADISON

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

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

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

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

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

CS/ECE 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

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

CENG3420 Lab 2-1: LC-3b Simulator

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

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

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

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

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

The Stored Program Computer

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

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

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

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

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

CPU ARCHITECTURE. QUESTION 1 Explain how the width of the data bus and system clock speed affect the performance of a computer system.

Computer Architecture

Logistics. IIT CS 350 S '17 - Hale

ARM Cortex-M4 Programming Model Memory Addressing Instructions

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

Memory General R0 Registers R1 R2. Input Register 1. Input Register 2. Program Counter. Instruction Register

Review Topics. Midterm Exam Review Slides

Implementing Functions at the Machine Level

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

Review Topics. Midterm Exam Review Slides

Topic 10: Instruction Representation

ECE 206, Fall 2001: Lab 3

Chapters 5. Load & Store. Embedded Systems with ARM Cortex-M. Updated: Thursday, March 1, 2018

Microprocessors. Microprocessors and rpeanut. Memory. Eric McCreath

Microprocessors and rpeanut. Eric McCreath

Memory Usage in Programs

are Softw Instruction Set Architecture Microarchitecture are rdw

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

A Bit of History. Program Mem Data Memory. CPU (Central Processing Unit) I/O (Input/Output) Von Neumann Architecture. CPU (Central Processing Unit)

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

General purpose registers These are memory units within the CPU designed to hold temporary data.

The PAW Architecture Reference Manual

CS 135: Computer Architecture I

Processor design - MIPS

ECE 411, Exam 1. Good luck!

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

ARM Shift Operations. Shift Type 00 - logical left 01 - logical right 10 - arithmetic right 11 - rotate right. Shift Amount 0-31 bits

Lecture 4: Instruction Set Architectures. Review: latency vs. throughput

LC-2 Programmer s Reference and User Guide

LC3DataPath ECE2893. Lecture 9a. ECE2893 LC3DataPath Spring / 14

Microcontroller Systems

Programmable Machines

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


CMPUT101 Introduction to Computing - Summer 2002

Comparison InstruCtions

Programmable Machines

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

Review Topics. Final Exam Review Slides

Fundamentals of Computer Architecture. 8. Bringing It All Together The Hardware Engineer s Perspective

The Von Neumann Architecture Odds and Ends. Designing Computers. The Von Neumann Architecture. CMPUT101 Introduction to Computing - Spring 2001

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

Architectures & instruction sets R_B_T_C_. von Neumann architecture. Computer architecture taxonomy. Assembly language.

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

( input = α output = λ move = L )

Transcription:

LC3 Memory Text: Introduction to Computer Systems : Sections 5.1.1, 5.3

John Von Neumann (1903-1957) Princeton / Institute for Advanced Studies Need to compute particle interactions during a nuclear reaction (Manhattan Project) EDVAC (First US Digital Computer)

Von Neumann Architecture Memory MAR MDR Input Processing Unit ALU R1 R2 R3 R4 R5 R6 R7 Output Control Unit PC CC IR

LC3 Memory RAM Hardware Data width = 16 bits (1 word) Address with = 16 bit (1 word) 2 16 = 65,536 rows with addresses 0x0000 0xFFFF Each word may contain either data or instruction VonNeumann instructions and data use same memory 0xffff 0x01c7 0xfffe 0xdaf3 0xfffd 0xed00 0xffffc 0xbe1c 0xfffb 0xef16 0x0c09 0x0000 0x0c08 0x0000 0x0c07 0x013f 0x0c06 0x184a 0x0c05 0x0001... 0x0003 0x0000 0x0002 0x0000 0x0001 0x0000 0x0000 0x03ff

LC3 Memory Read MAR Memory Address Register Contains address of memory to read from MDR Memory Data Register Read copies value in memory at MAR address into MDR MAR 0x0c07 MDR 0x013F 0xffff 0xfffe 0xfffd 0xffffc 0xfffb 0x0c09 0x0c08 0x0c07 0x0c06 0x0c05. 0x0003 0x0002 0x0001 0x0000 0xdaf3 0xed00 0xbe1c 0xef16 0x0000 0x0000 0x013f 0x184a 0x0001 0x0000 0x0000 0x0000 0x03ff

LC3 Memory Write MAR Memory Address Register Contains address of memory to write to MDR Memory Data Register Write copies value in MDR to memory at MAR address MAR 0x0c07 MDR 0x3333 0xffff 0xfffe 0xfffd 0xffffc 0xfffb 0x0c09 0x0c08 0x0c07 0x0c06 0x0c05. 0x0003 0x0002 0x0001 0x0000 0xdaf3 0xed00 0xbe1c 0xef16 0x0000 0x0000 0x3333 0x184a 0x0001 0x0000 0x0000 0x0000 0x03ff

Instruction Register 16 bit register in the Control Unit Contains the instruction currently being executed IR 0x1283 0x1283 = 0001 001 010 000 011 or ADD r1,r2,r3

Program Counter (PC) 16 bit register in Control Unit Contains Address of the next instruction to be executed Initialized to address of first instruction when program is loaded Incremented (+1) when instruction is read Some instructions read or write to the PC register (more to come) PC 0x301C

LC3 Instruction Cycle (1 st Draft) Start at x3000 Read Instruction Move to Next Instruction Process Instruction HALT

LC3 Instruction Cycle Fetch Instruction Store Results Decode Execute Evaluate Address Fetch Operands

Fetch Instruction Internal Details Fetch Instruction Copy PC to MAR Read Memory at MAR into MDR (Read instruction @ PC) Copy MDR to IR Make PC ALU Operand A Make 1 ALU Operand B Tell ALU to ADD Store Result in PC (PC PC+1) Note: After Fetch Instruction, PC points at NEXT instruction! Store Results Execute Fetch Operands Decode Evaluate Address

Decode Internal Details Fetch Instruction Use OPCODE in IR (first 4 bits) to determine How the rest of the instruction register should be read Which phases of instruction cycle are needed * What control signals are sent to memory, processing unit, I/O in each relevant phase Use remaining (last 12) bits to determine Source Register(s) Destination Register Immediate Values (padded to 16 bits) Store Results Execute Fetch Operands Decode Evaluate Address * Different instructions use different subsets of the last 4 phases

Load Instruction Assembly Mnemonic: LD Destination Register (Rz) Offset e.g. ld R1,#12 Object Opcode: 0010 (0x2) DR (3 bit subfield) PCoffset9 (9 bit subfield) e.g. 0b0010 001 0 0000 1100 =0x220C Adds value in PC to offset, writes to MAR, reads memory, copies MDR to Destination Register (Rz)

PC/Offset Address Mode 16 bit instruction too small for both op-code and 16 bit address Most data is close to current instruction in memory Calculate effective address by adding PC offset to PC PC offset may be positive or negative Effective address may be above or below current instruction In Assembly, label reference is the same as a PC offset! Label reference is converted to a PC offset by Assembler One instruction must refer to a single memory location REMEMBER: PC points to instruction AFTER current instruction!

Load Register Instruction Assembly Mnemonic: LDR Destination Register (Rz) Base Register (Rb) Offset e.g. ldr R1,R3,#3 Object Opcode: 0110 (0x6) DR (3 bit subfield) BaseR (3 bit subfield) Offset6 (6 bit subfield) e.g. 0b0110 001 011 00 0011 =0x62C3 Adds value in Base Register (Rb) to offset, writes to MAR, reads memory, copies MDR to Destination Register (Rz)

Base/Offset Address Mode 16 bit instruction too small for both op-code and 16 bit address Calculate effective address by adding offset to base register Offset may be positive or negative or zero Effective address may be above or below or at where base register points One instruction may point to different memory locations! Execute the same instruction with different base register values Q: How do you get an address in a register?

Load Effective Address Assembly Mnemonic: LEA Destination Register (Rz) Offset e.g. lea R1,#12 Object Opcode: 1110 (0xE) DR (3 bit subfield) PCoffset9 (9 bit subfield) e.g. 0b1110 001 0 0000 1100 =0xE20C Adds value in PC to offset, writes to Destination Register (Rz)

Evaluate Address Internal Details Fetch Instruction No action for ADD, AND, NOT Store Results Decode For PC/Offset instructions (LD, LEA, etc.) Copy PC to ALU operand A Copy Pcoffset9, sign extended, to ALU operand B For Base/Offset instructions (LDR, etc.) Copy Rb to ALU operand A Copy Offset6, sign extended, to ALU operand B Tell ALU to Add Copy result to MAR Execute Fetch Operands Evaluate Address

Fetch Operands Internal Details Fetch Instruction For ADD, AND, NOT, copy SR1 to ALU operand A For ADD, AND, copy either SR2 or IMM5 to ALU operand B For LD and LDR, read memory at MAR Store Results Execute Fetch Operands Decode Evaluate Address

Execute Internal Details Fetch Instruction No action for LD, LDR, LEA For ADD, Tell ALU to Add For AND, Tell ALU to And For NOT, Tell ALU to invert Store Results Execute Fetch Operands Decode Evaluate Address

Store Results Internal Details Fetch Instruction For ADD, AND, NOT, store ALU result to DR For LD, LDR, copy MDR to DR For LEA, copy MAR to DR Store Results Execute Fetch Operands Decode Evaluate Address

Store Instruction Assembly Mnemonic: ST Source Register (Rs) Offset e.g. st R1,#12 Object Opcode: 0011 (0x3) SR (3 bit subfield) PCoffset9 (9 bit subfield) e.g. 0b0011 001 0 0000 1100 =0x320C Adds value in PC to offset, writes to MAR, copies Source Register (Rs) value to MDR, writes memory NOTE: BACKWARDS INSTRUCTION (Rs Memory)

Store Register Instruction Assembly Mnemonic: STR Source Register (Rs) Base Register (Rb) Offset e.g. str R1,R3,#6 Object Opcode: 0111 (0x7) SR (3 bit subfield) BaseR (3 bit subfield) Offset6 (6 bit subfield) e.g. 0b0111 001 011 00 0110 =0x72C6 Adds value in Base Register (Rb) to offset, writes to MAR, copies Source Register (Rs) value to MDR, writes memory NOTE: BACKWARDS INSTRUCTION (Rs Memory)

LD/ST vs LDR/STR LD R3,COUNT ST R6,ANSWER Cannot read or write unlabeled addresses e.g. LD R4,DATA+3 Every time this instruction is executed, it references the SAME memory Cannot read or write vectors or arrays LD/ST Used for single fixed variables LDR/STR Used for arrays/vectors/offsets Almost always preceded by LEA Especially useful in looping code 3 rd argument is fixed (usually #0) LD R1,OFFSET LEA R2,DATA ADD R1,R1,R2 LDR R3,R1,#0 ADD R3,R3,#10 STR R3,R1,#0

LC3 Program Layout (No Branches).orig always first Next is your code End with HALT Followed by data.end always last

LC3 Example Program: Specifications Read the first memory location after the program. Write that value+1 in the second memory location after the program, and that value+2 in the third memory location after the program.

Example LC3 Program.orig x3000 LD R1,#??? ADD R1,R1,#1 ST R1,#??? ADD R1,R1,#1 ST R1,#??? HALT.fill #15.fill #0.fill #0.end

Example LC3 Program.orig x3000 x3000 LD R1,#??? Current Instruction x3001 ADD R1,R1,#1 PC = x3001 x3002 ST R1,#??? PC+1 x3003 ADD R1,R1,#1 PC+2 x3004 ST R1,#??? PC+3 x3005 HALT PC+4 x3006.fill #15 PC+5 x3007.fill #0 x3008.fill #0.end

Example LC3 Program.orig x3000 x3000 LD R1,#5 x3001 ADD R1,R1,#1 x3002 ST R1,#??? Current Instruction x3003 ADD R1,R1,#1 PC x3004 ST R1,#??? PC+1 x3005 HALT PC+2 x3006.fill #15 PC+3 x3007.fill #0 PC+4 x3008.fill #0.end

Example LC3 Program.orig x3000 x3000 LD R1,#5 x3001 ADD R1,R1,#1 x3002 ST R1,#4 x3003 ADD R1,R1,#1 x3004 x3005 ST R1,#??? HALT Current Instruction PC x3006.fill #15 PC+1 x3007.fill #0 PC+2 x3008.fill #0 PC+3.end

Example LC3 Program.orig x3000 LD R1,#5 ADD R1,R1,#1 ST R1,#4 ADD R1,R1,#1 ST R1,#3 HALT.fill #15.fill #0.fill #0.end