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

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

EEL 5722C Field-Programmable Gate Array Design

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

Instruction Set Architecture

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

Computing Layers. Chapter 5 The LC-3

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

CS 2461: Computer Architecture I

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

COSC121: Computer Systems: Review

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

COSC121: Computer Systems: Review

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

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

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

LC-3 Instruction Set Architecture. Textbook Chapter 5

LC-3 Instruction Set Architecture

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

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

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

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

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

appendix a The LC-3 ISA A.1 Overview

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

UNIVERSITY OF WISCONSIN MADISON

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

LC-3 Instruction Processing

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

Memory Usage in Programs

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

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

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

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 COMPUTER SCIENCES DEPARTMENT UNIVERSITY OF WISCONSIN-MADISON

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

ECE 206, Fall 2001: Lab 3

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?

Midterm 2 Review Chapters 4-16 LC-3

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

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

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

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

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 4 The Von Neumann Model

Chapter 6 Programming the LC-3

Special Microarchitecture based on a lecture by Sanjay Rajopadhye modified by Yashwant Malaiya

11/28/2016. ECE 120: Introduction to Computing. Register Loads Control Updates to Register Values. We Consider Five Groups of LC-3 Control Signals

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

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

Chapter 4 The Von Neumann Model

Major and Minor States

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

LC-2 Programmer s Reference and User Guide

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

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

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

Chapter 9 TRAP Routines and Subroutines

Chapter 9 TRAP Routines and Subroutines

CS 135: Computer Architecture I

Microprogrammed Control. ECE 238L μseq 2006 Page 1

Chapter 9 TRAP Routines and Subroutines

System Calls. Chapter 9 TRAP Routines and Subroutines

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

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

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

ISA Instruction Operation

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

Logistics. IIT CS 350 S '17 - Hale

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

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

CS 2461: Computer Architecture I

The MARIE Architecture

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

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

( input = α output = λ move = L )

LC-3 Architecture. (Ch4 ish material)

Implementing Functions at the Machine Level

Microprocessors. Microprocessors and rpeanut. Memory. Eric McCreath

Microprocessors and rpeanut. Eric McCreath

Computer Architecture. Lecture 5: Multi-Cycle and Microprogrammed Microarchitectures

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

Lec-memMapIOtrapJSR SYS_BUS

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

Programming Studio #4 ECE 190

CS 270 Fall 2013 Mock Final

The Assembly Language of the Boz 5

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

This simulated machine consists of four registers that will be represented in your software with four global variables.

Basic Processing Unit: Some Fundamental Concepts, Execution of a. Complete Instruction, Multiple Bus Organization, Hard-wired Control,

Computer Systems Architecture I. CSE 560M Lecture 3 Prof. Patrick Crowley

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

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

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

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

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

Transcription:

LC- ISA - II Lecture Topics LC- data movement instructions LC- control instructions LC- data path review Lecture materials Textbook 5. - 5.6 Textbook Appendix A. Homework HW due Wednesday February 2 at 5pm in the ECE 190 drop-off box Machine problem MP2 due March 2, 2011 at 5pm submitted electronically. Announcements 1 V. Kindratenko

LC- data movement instructions Overview Load: move data from memory to o LD, LDI, LDR o LEA immediate mode load instruction Store: o ST, STR, STI Load/store instruction format destination or source address generation bits 4 ways to interpret address generation bits (4 addressing modes) o PC-relevant mode (LD and ST instructions) o Indirect mode (LDI and STI instructions) o Base + offset mode (LDR and STR instructions) o Immediate mode (LEA instruction) Load instruction using base + offset addressing mode (LDR) Operation: the content of memory at the address computed as the sum of the address stored in the base address (BaseR) and the sign-extended last 6 bits of the instruction (offset6) is loaded into the destination (DR) o DR mem[baser+sext(offset6)] o setcc LDR 0 1 1 0 destination base address offset6 o Example: 0110 001 010 011101; LDR R1, R2, offset 2 V. Kindratenko

IR DR BaseR x1d 0 1 1 0 0 0 1 0 1 0 0 1 1 1 0 1 6 IR[5:0] xabcd x245 R0 R1 R2 R R4 R5 R6 R7 SEXT N Z P 1 0 0 ADD x262 MAR MDR x262 xabcd MAR R2 + SEXT(IR[5:0]) MDR mem[mar] R1 MDR offset6 field is 6-bit wide, thus the offset can be from -2 to +1 Store instruction using base + offset addressing mode (STR) Operation: value stored in the source (SR) is transferred to the memory at the address computed as the sum of the address stored in the base address (BaseR) and the signextended last 6 bits of the instruction (offset6) o mem[baser+sext(offset9)] SR STR 0 1 1 1 source base address offset6 o Example: 0111 001 010 011101; STR R1, R2, offset V. Kindratenko

IR SR BaseR x1d 0 1 1 1 0 0 1 0 1 0 0 1 1 1 0 1 6 IR[5:0] xfedc x245 R0 R1 R2 R R4 R5 R6 R7 SEXT ADD x262 MAR MDR x262 xfedc MAR R2 + SEXT(IR[5:0]) MDR R1 mem[mar] MDR Load instruction using PC relative addressing mode (LD) Operation: the content of memory at the address computed as the sum of the address stored in PC and the sign-extended last 9 bits of the instruction (PCoffset9) is loaded into the destination (DR) o DR mem[pc+sext(pcoffset9)] o setcc LD 0 0 1 0 destination PCoffset9 o Example: 0010 000 110101111; LD R0, offset 4 V. Kindratenko

PC IR 0 0 1 0 0 0 0 1 1 0 1 0 1 1 1 1 x4018 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 1 DR x1af 9 IR[8:0] SEXT 0011001100110011 R0 R1 R2 R R4 R5 R6 R7 N Z P 0 0 1 ADD xfc8 MAR MDR xfc8 0011001100110011 MAR PC + SEXT(IR[8:0]) MDR mem[mar] R0 MDR Store instruction using PC relative addressing mode (ST) Operation: value stored in the source (SR) is transferred to the memory at the address computed as the sum of the address stored in PC and the sign-extended last 9 bits of the instruction (PCoffset9) o mem[pc+sext(pcoffset9)] SR ST 0 0 1 1 source PCoffset9 o Example: 0011 000 110101111; ST R0, offset 5 V. Kindratenko

PC IR 0 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 x4018 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 1 SR x1af 9 IR[8:0] SEXT 1111111111110000 R0 R1 R2 R R4 R5 R6 R7 ADD xfc8 MAR MDR xfc8 1111111111110000 MAR PC + SEXT(IR[8:0]) MDR R0 mem[mar] MDR PCoffset9 field is 9-bit wide, thus the offset can be from -256 to +255 Load instruction using indirect addressing mode (LDI) Operation: the content of memory at the address stored in memory at the address computed as the sum of the address stored in PC and the sign-extended last 9 bits of the instruction (PCoffset9) is loaded into the destination (DR) o DR mem[mem[pc+sext(pcoffset9)]] o setcc LDI 1 0 1 0 destination PCoffset9 6 V. Kindratenko

o Example: 1010 011 111001100; LDI R, offset DR PC IR 1 0 1 0 0 1 1 1 1 1 0 0 1 1 0 0 x4a1c 0 1 0 0 1 0 1 0 0 0 0 1 1 1 0 0 x1cc 9 IR[8:0] SEXT xffff R0 R1 R2 R R4 R5 R6 R7 N Z P 1 0 0 ADD x49e8 MAR MDR x2110 x49e8 xffff x2110 MAR PC + SEXT(IR[8:0]) MDR mem[mar] MAR MDR MDR mem*mar+ R MDR Store instruction using indirect addressing mode (STI) Operation: value from the source (SR) is transferred to the memory at the address stored in memory at the address computed as the sum of the address stored in PC and the sign-extended last 9 bits of the instruction (PCoffset9) o mem[mem[pc+sext(pcoffset9)]] SR STI 1 0 1 1 source PCoffset9 o Example: 1011 011 111001100; STI R, offset 7 V. Kindratenko

SR PC IR 1 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 x4a1c 0 1 0 0 1 0 1 0 0 0 0 1 1 1 0 0 x1cc 9 IR[8:0] SEXT xaaaa R0 R1 R2 R R4 R5 R6 R7 ADD x49e8 MAR MDR x2110 x49e8 xaaaa x2110 MAR PC + SEXT(IR[8:0]) MDR mem[mar] MAR MDR MDR R mem*mar+ MDR LC- control instructions Control instructions change the sequence of the instructions that are executed. The achieve this by directly manipulating the value of PC. Control instructions supported by LC- o JMP - unconditional jump o BR conditional branch o TRAP invokes an OS service call o JSR/JSRR subroutine call o RET return from subroutine o RTI return from interrupt For now we will study only JMP, BR, and TRAP instructions Conditional branches (BR) Operation: if any of the condition codes tested is set, increment the PC with the sign-extended PCoffset9 (bits 0-8 of the instruction). In other words, branch is taken if specified condition is true. 8 V. Kindratenko

o If (n AND N) OR (z AND Z) OR (p AND P)) then PC PC + SEXT(PCoffset9) BR 0 0 0 0 n z p condition codes to test PCoffset9 PCoffset range is from (2) 8 to 2 8-1 PC +1 PCMUX #0 #1 1 N Z P IR 0 0 0 0 n z p 9 IR[8:0] ADD SEXT Instruction cycle for BR: o FETCH AND DECODE phases are the same as for any other instruction Note that PC PC + 1 during the FETCH phase o EVALUATE ADDRESS phase: compute PC + SEXT(PCoffset9) o EXECUTE phase Condition codes N,Z,P for which corresponding bits n,z,p are set in the instruction are examined,.e.g., If n=1, N condition code ins checked 9 V. Kindratenko

If the condition code that was examined is set, the branch is taken, that is PC PC + SEXT(PCoffset9) Otherwise, no branch is taken, that is, PC PC If all bits n,z,p of the instruction are set, then all condition codes N,Z,P are examined, and since at least one of them must be set, the condition is always met, and the branch is always taken, essentially unconditionally. Example1: o Z=1, N=P=0 o PC: x4027 o IR: 0000 010 011011001; BRz, x0d9 o Outcome: PC x4027 + x1 + x0d9 (PC x4101) Example2: o For any N,Z, P o PC: x507b o IR: 0000 111 110000101; BRnzp, x185 o Outcome: PC x507b + x1 + x185 (PC x5001) Example: o N=1, Z=P=0 o PC: x000 o IR: 0000 100 111111111; BRz. #-1 o Outcome: PC x000 + x1 - #1 (PC x000) Multiplication example Write a program that computes a product of two integers: a x b = p a and b are 2 s complement numbers we will impose a restriction that b > 0 algorithm: replace product with the sum: p = a + a +.. + a (b times) o we will use R0 to hold value of a o we will use R1 to hold value of b o we will use R2 to hold value of p o our program will be located in memory starting at the address x000 o before the program starts value of a is located in memory at the address x010 value of b is located in memory at the address x011 o when the program is done, value of p should be located in memory at the address x012 First, we represent the algorithm for solving our problem as a flowchart Next, we translate the flowchart, step by step, into a program in machine language o We save the program (binary instruction column and optionally comments column only!) into a fine with extension.bin, e.g., mult.bin o Also need to add a line of code that specifies the starting address of the program o Convert it to an LC- executable: lcconvert mult.bin 10 V. Kindratenko

o Use either command line or graphical LC- simulator to run it command line LC- simulator: lcsim mult.obj graphical LC- simulator: lcsim-tk mult.obj no start Initialize: - get values of a and b from memory - clear value of p p = p + a have we done it b times? yes store value of p in memory addr binary instruction comments x000 0101 010 010 000000 R2 0 (AND, R0, R0, #0) x001 0010 000 000001110 R0 a (LD, R0, #14) x002 0010 001 000001110 R1 b (LD, R1, #14) x00 0001 010 010 0 00 000 R2 R2+R0 (ADD R2, R2, R0) x004 0001 001 001 1 11111 R1 R1-1 (ADD R1, R1, #-1) x005 0000 001 111111101 PC x00 (BRp, #-) x006 0011 010 000001011 p R2 (ST R2, #11) x007 1111 0000 00100101 HALT x008 x009 x00a x00b x00c x00d x00e x00f x010 a is stored here x011 b is stored here x012 p is to be stored here stop Unconditional jump (JMP) Operation: load the PC with the contents of the specified by bits 6-8 o PC BaseR JMP 1 1 0 0 0 0 0 0 0 0 0 0 0 BaseR o Example: 1100 000 111 000000; JMP R7 11 V. Kindratenko

BaseR R0 R1 PC IR 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 x4000 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x4000 R2 R R4 R5 R6 R7 JMP instruction has no limitations on where the next instruction to be executed is located since the full -bit memory address can be stored in the. TRAP Operation: changes PC to a memory address that is a part of the OS. As the result, OS gets control an executes some task on behalf of our program o PC mem*trap vector] TRAP 1 1 1 1 0 0 0 0 unused trap vector TRAP instruction invokes an operating system service call identified by bits 7:0 of the instruction For now, remember the following trap vectors: o x2 allows to input a character from the keyboard, its value will be placed in R0 o x21 allows to output a character to the display (R0[7:0] are written out) o x25 halts the program we will look at the implementation details of TRAP instruction later (Ch 9) LC- data path review The LC- data path consist of all the components that process the information during an instruction cycle o The functional unit that operates on the information o The s that store the information o Buses and wires that carry information from one point to another Basic components of the data path: 12 V. Kindratenko

The global bus o LC- global bus consists of wires and associated electronics o It allows one structure to transfer up to bits of information to another structure by making the necessary electronic connections on the bus o Exactly one value can be translated on the bus at a time o Each structure that supplies values to the bus connects to it via a tri-state device that allows the computer s control logic to enable exactly one supplier of information to the bus at a time o The structure wishing to obtain information from the bus can do so by asserting (setting to 1) its LD.x (load enable) signal. Memory o Memory in LC- is accessed by loading the memory address value into MAR o The result of memory read is stored in MDR o The computer s control logic supplies the necessary control signals to enable the read/write of memory The ALU and the file o The ALU is the processing element Has two inputs and one output Inputs come directly from the file One of the inputs can also be supplied directly from the IR, controlled by the SR2MUX Output goes to the bus o It then is stores in the file and Processed by some additional circuitry to generate the condition codes N,Z,P The file consists of 8 -bit s It can supply up to two values via its two output ports It can store one value, coming from the bus Read/write access to the file is controlled by the -bit resister signals, DR, SR1, SR2 The PC and PCMUX o The PC supplies via the global bus to the MAR the address of the instruction to be fetched at the start of the instruction cycle. The PC itself is supplied via the three-toone PCMUX, depending on the instruction being executed o During the fetch cycle, the PC is incremented by 1 and written to the PC o If the executed instruction is a control instruction, then the relevant source of the PCMUX depends on the type of the control instruction and is computed using a special ADD unit The MARMUX o Controls which of two sources will supply memory address to MAR 1 V. Kindratenko

o It is either the value coming form the instruction needed to implement TRAP instruction, or the value computed based on the PC or a value stored in one of the general-purpose s LC- instruction cycle revisited o FETC IR contains the fetched instruction PC is incremented by 1 o DECODE Instruction is decoded resulting in control logic providing various control signals to the computer o EVALUATE ADDRESS Address of memory to be accessed during the execution of the instruction is computed Memory access instructions require this phase o OPERAND FETCH The data from memory is loaded into MDR o EXECUTE ALU is directed to perform the operation Memory access instructions do not have this phase o STORE RESULTS Results are stored to memory or s, depending on the instruction 14 V. Kindratenko