Chapter 5 The LC-3.

Slides:



Advertisements
Similar presentations
Chapter 4 The Von Neumann Model
Advertisements

Chapter 4 The Von Neumann Model
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Computer Science 210 Computer Organization Strings, I/O, and Trap Service Routines.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Four Trusses.
Introduction to Computer Engineering ECE 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin –
The LC-3 – Chapter 6 COMP 2620 Dr. James Money COMP
Chapter 10 And, Finally.... Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display A Final Collection of ISA-related.
PART 6 Programming 1.Decomposition 2.Three Constructs 3.Counting Example 4.Debugging.
Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 Subroutines.
Chapter 5 The LC-3 Instruction Set Architecture l ISA Overview l Operate instructions l Data Movement instructions l Control Instructions l LC-3 data path.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language.
CS25410 Memory Machine Code. Common types of non-rotating memory (1) RAMRandom Access Memory In reality, read/write memory This is usually volatile, meaning.
Chapter 5 The LC-3.
Chapter 4 - ISA 1.The Von Neumann Model. 4-2 The Stored Program Computer 1943: ENIAC Presper Eckert and John Mauchly -- first general electronic computer.
LC-3 Computer LC-3 Instructions
S. Barua – CPSC 240 CHAPTER 5 THE LC-3 Topics Memory organization Registers Instruction set Opcodes.
Overview The Operate Instructions - ADD, AND, NOT The Data Movement Instructions - Load, Load Address, Store Example Using Operate & Data Movement The.
LC-3 Instruction Set Architecture (Textbook’s Chapter 5)
Chapter 5 The LC-3 LC-3 Computer Architecture Memory Map
Chapter 6 Programming in Machine Language The LC-3 Simulator
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
LC-3 Instruction Set Architecture
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Image Slides.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Chapter 5 The LC-3. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 5-2 Instruction Set Architecture ISA.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 5 The LC-2 Instruction Set Architecture Operate instructions Data Movement instructions.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 4 The Von Neumann Model Basic components Instruction processing.
Chapter 4 The Von Neumann Model
Introduction to Computing Systems from bits & gates to C & beyond Chapter 5 The LC-3 Instruction Set Architecture ISA Overview Operate instructions Data.
Chapter 5 The LC Instruction Set Architecture ISA = All of the programmer-visible components and operations of the computer memory organization.
Chapter 5 The LC-3. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 5-2 Data Movement Instructions Load --
Introduction to Computer Engineering CS/ECE 252, Fall 2009 Prof. Mark D. Hill Computer Sciences Department University of Wisconsin – Madison.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
The LC-3. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 5-2 Instruction Set Architecture ISA = All of the.
Chapter 5 The LC Instruction Set Architecture ISA = All of the programmer-visible components and operations of the computer memory organization.
Functions. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 JSR Instruction Jumps to a location (like.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
March R. Smith - University of St Thomas - Minnesota ENGR 330: Today’s Class Connecting Hardware to InstructionsConnecting Hardware to Instructions.
Elements of Datapath for the fetch and increment The first element we need: a memory unit to store the instructions of a program and supply instructions.
The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP
Introduction to Computing Systems and Programming The LC-2.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Chapter 13 Transportation Demand Analysis. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display
Computer Science 210 Computer Organization Machine Language Instructions: Control.
LC-3 Datapath ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin – Madison.
Computer Science 210 Computer Organization
Chapter 4 The Von Neumann Model
Copyright © The McGraw-Hill Companies, Inc
Computer Science 210 Computer Organization
Chapter 5 The LC-3.
The LC-3 Instruction Set Architecture Data Movement instructions
LC-3 Details and Examples
Computer Science 210 Computer Organization
Chapter 3 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 5 The LC-3.
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Chapter R A Review of Basic Concepts and Skills
Chapter 9 TRAP Routines and Subroutines
Chapter 4 The Von Neumann Model
The Stored Program Computer
Copyright © The McGraw-Hill Companies, Inc
CHAPTER 6 SKELETAL SYSTEM
Chapter 3 Introduction to Physical Design of Transportation Facilities.
Chapter 5 The LC-3.
Presentation transcript:

Chapter 5 The LC-3

Control Instructions 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)

Condition Codes LC-3 has three condition code registers: N -- negative Z -- zero P -- positive (greater than zero) Set by any instruction that writes a value to a register (ADD, AND, NOT, LD, LDR, LDI, LEA) Exactly one will be set at all times Based on the last instruction that altered a register

Branch Instruction 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. If the branch is not taken, the next sequential instruction is executed.

BR (PC-Relative) What happens if bits [11:9] are all zero? All one? If all zero, no CC is tested, so branch is never taken. (See Appendix B.) If all one, then all are tested. Since at least one of the CC bits is set to one after each operate/load instruction, then branch is always taken. (Assumes some instruction has set CC before branch instruction, otherwise undefined.) What happens if bits [11:9] are all zero? All one?

Example from last class: Multiply value stored in R2 by 15 ; initialize 0101 000 000 1 00000 ; R0 <- R0 AND 0 0101 001 001 1 00000 ; R1 <- R1 AND 0 ; code to repeat 0001 001 001 000 010 ; R1 <- R1 + R2 0001 000 000 1 00001 ; R0 <- R0 + 1 ; set condition codes 0001 011 000 1 10001 ; R3 <- R0 – 15 ; branch if R3 < 0 because count < 15 0000 100 111111100 ; PC<- PC- 4 if n==1 R0 <- R0 AND 0 R1 <- R1 AND 0 R1 <- R1 + R2 R0 <- R0 + 1 R3 <- R0 -15 true R3 < 0? n==1 false

Refined Example: a better way to count ; initialize 0101 000 000 1 00000 ; R0 <- R0 AND 0 0101 001 001 1 00000 ; R1 <- R1 AND 0 0001 000 000 1 01111 ; R0 <- R0 + 15 ; code to repeat 0001 001 001 000 010 ; R1 <- R1 + R2 0001 000 000 1 11111 ; R0 <- R0 - 1 ; set condition codes 0001 011 000 1 10001 ; R3 <- R0 – 15 ; branch if R0 >0 because count < 15 0000 001 111111101 ; PC<- PC- 3 if p==1 R0 <- R0 AND 0 R1 <- R1 AND 0 R0 <- R0 + 15 R1 <- R1 + R2 R0 <- R0 -1 true R0 > 0? p==1 false

Iterative Do-While Loop While Loop true false

Multiply Using the While Loop Structure R0 <- R0 AND 0 ; initialize 0101 000 000 1 00000 ; R0 <- R0 AND 0 0101 001 001 1 00000 ; R1 <- R1 AND 0 0001 000 000 1 01111 ; R0 <- R0 + 15 ; branch if R0== 0 because count == 15 0000 010 000000011 ; PC<- PC+3 if z==1 ; code to repeat 0001 001 001 000 010 ; R1 <- R1 + R2 0001 000 000 1 11111 ; R0 <- R0 - 1 ; branch unconditionally 0000 111 111111100 ; PC<- PC-4 R1 <- R1 AND 0 R0 <- R0 + 15 true R0 == 0? z==1 false R1 <- R1 + R2 R0 <- R0 -1 always true true false

Unconditional branch to retest condition Code for Iteration PC offset to address C Exact bits depend on condition being tested true false Unconditional branch to retest condition PC offset to address A Assumes all addresses are close enough that PC-relative branch can be used.

Conditional If If-Else "hammock" "diamond"

WRONG??? If conditional Problem statement: Increment R0 if R0 < R1 R0 <- NOT R0 ; form 2s complement of R0 1001 000 000 111111 ; R0 <- NOT R0 0001 000 000 1 00001 ; R0 <- R0 + 1 ; R3 <- R1 + complement of R0 0001 011 000 000 001 ; R3 <- R0 + R1 ; branch if R3 is neg or 0 0000 110 000000001 ; PC<- PC+1 if z==1 or n==1 ; increment R0 1111000000100101 ; halt R0 <- R0 + 1 R3 <- R0 + R1 true z==1 R3 <= 0? n==1 false R0 <- R0 +1 false

Analyze the Situation Goal: Increment R0 if R0 < R1 R0 and R1 can each be positive or negative So  increment R0 if (R1-R0) is positive and branch to skip that step if (R1-R0) is zero or negative when we don’t want to increment -> we do want to branch Assume R0 >= R1 result of (R1-R0) R0 is pos & R1 is pos zero or neg R0 is pos & R1 is neg neg R0 is neg & R1 is pos NA pos R0 is neg & R1 is neg zero, neg

If conditional (CORRECTED) Problem statement: Increment R0 if R0 < R1 ; form 2s complement of R0 & store in R4 1001 100 000 111111 ; R4 <- NOT R0 0001 100 100 1 00001 ; R4 <- R4 + 1 ; R3 <- R1 + complement of R0 (stored in R4) 0001 011 100 000 001 ; R3 <- R4 + R1 ; branch if R3 is neg or 0 0000 110 000000001 ; PC<- PC+1 if z==1 or n==1 ; increment R0 0001 000 000 1 00001 ; R0 <- R0 + 1 1111000000100101 ; halt R0 <- NOT R0 R0 <- R0 + 1 R3 <- R0 + R1 true R3 <= 0? z==1 n==1 false R0 <- R0 +1 false

Unconditional branch to Next Subtask Code for Conditional PC offset to address C Exact bits depend on condition being tested Unconditional branch to Next Subtask PC offset to address D Assumes all addresses are close enough that PC-relative branch can be used.

JMP (Register) Jump is an unconditional branch -- always taken. Target address is the contents of a register. Allows any target address.

TRAP Calls a service routine, identified by 8-bit “trap vector.” When routine is done, PC is set to the instruction following TRAP. (We’ll talk about how this works later.) vector routine x23 input a character from the keyboard (IN) x21 output a character to the monitor (OUT) x25 halt the program (HALT) Warning: TRAP changes R7.