Sequencing, Selection, and Loops in Machine Language

Slides:



Advertisements
Similar presentations
The Fetch – Execute Cycle
Advertisements

Chapter 1. Basic Structure of Computers
Microprocessors.
Central Processing Unit
Programming 68HC11.
2.3) Example of program execution 1. instruction  B25 8 Op-code B means to change the value of the program counter if the contents of the indicated register.
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
S. Barua – CPSC 240 CHAPTER 5 THE LC-3 Topics Memory organization Registers Instruction set Opcodes.
CHAPTER 5 COMPUTER SYSTEMS ORGANIZATION. REMEMBER... Computer science is the study of algorithms including * Their formal and mathematical properties---
Chapter 6 In introduction to System Software and Virtual Machine ***Assembly Language.
Computer Processing CSCE 110 J. Michael Moore.
Basic Computer Organization, CPU L1 Prof. Sin-Min Lee Department of Computer Science.
Elements of the Computer (How a processor works)
Dale & Lewis Chapter 5 Computing components. Let’s design a computer Generic CPU with registers −Program counter (PC) – 5 bits (size of addresses) −Instruction.
Introduction to computer: executes instructions. Overview Topics discussed in this webnote: –Structure and operation of the CPU –Program flow –Types of.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
5-Stage Pipelining Fetch Instruction (FI) Fetch Operand (FO) Decode Instruction (DI) Write Operand (WO) Execution Instruction (EI) S3S3 S4S4 S1S1 S2S2.
Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data.
Computer Science 101 Assembly Language. Problems with Machine Language Uses binary - No English-like words to make it more readable Uses binary - No English-like.
Computer Science 101 How the Assembler Works. Assembly Language Programming.
CPU Design. Introduction – The CPU must perform three main tasks: Communication with memory – Fetching Instructions – Fetching and storing data Interpretation.
Von Neumann Machine Objectives: Explain Von Neumann architecture:  Memory –Organization –Decoding memory addresses, MAR & MDR  ALU and Control Unit –Executing.
Invitation to Computer Science 6th Edition Chapter 5 Computer Systems Organization.
Execution of an instruction
Lecture 14 Today’s topics MARIE Architecture Registers Buses
CS 111 – Sept. 15 Chapter 2 – Manipulating data by performing instructions “What is going on in the CPU?” Commitment: –Please read through section 2.3.
Important Concepts  Parts of the CPU  Arithmetic/Logic Unit  Control Unit  Registers  Program Counter  Instruction Register  Fetch/Decode/Execute.
1 Purpose of This Chapter In this chapter we introduce a basic computer and show how its operation can be specified with register transfer statements.
Lec 5 Basic Computer Organization
Computer Science 101 Computer Systems Organization ALU, Control Unit, Instruction Set.
CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
Computer Science 101 Computer Systems Organization Machine Language Examples Entire machine.
M. Mateen Yaqoob The University of Lahore Spring 2014
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Machine Instructions.
September 26, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 2: Implementation of a Simplified Computer Jeremy R. Johnson Wednesday,
Represents different voltage levels High: 5 Volts Low: 0 Volts At this raw level a digital computer is instructed to carry out instructions.
ICC Module 3 Lesson 1 – Computer Architecture 1 / 26 © 2015 Ph. Janson Information, Computing & Communication Computer Architecture Clip 1 – Assembler.
Dale & Lewis Chapter 5 Computing components
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Chapter 5: Computer Systems Organization Invitation to Computer Science,
Jeremy R. Johnson William M. Mongan
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Program to multiply 2 numbers 500-Input x 291-Store acc. as x 500-Input y 292-Store acc. as y 193-Load y in to acc. (0 on 1 st parse) 391-Add x to acc.
Chapter 5 Computer Organization TIT 304/TCS 303. Purpose of This Chapter In this chapter we introduce a basic computer and show how its operation can.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
CS 270: Mathematical Foundations of Computer Science
Control Unit Lecture 6.
CPU Organisation & Operation
Chapter 4 The Von Neumann Model
Computer Science 210 Computer Organization
The fetch-execute cycle
The Processor and Machine Language
Computer Science 210 Computer Organization
Functional Units.
Computer Programming Machine and Assembly.
Design of the Control Unit for One-cycle Instruction Execution
Computer Science 210 Computer Organization
MARIE: An Introduction to a Simple Computer
Systems Architecture I (CS ) Lecture 2: A Simplified Computer
The Von Neumann Architecture Odds and Ends
CS Chapter 4 Dr. Clincy Professor of CS TODAY’S AGENDA
The Von Neumann Architecture
Program Execution.
Basic components Instruction processing
Information Representation: Machine Instructions
Lecture 18 Compilers and Language Translation (S&G, ch. 9)
Hmmm Assembly Language
CPSC 171 Introduction to Computer Science
CS 111 – Sept. 16 Machine language examples Instruction execution
Little Man Computer.
Presentation transcript:

Sequencing, Selection, and Loops in Machine Language Computer Science 101 Sequencing, Selection, and Loops in Machine Language

Sequencing Supported by the linear structure of memory Begin <statement 1> … <statement n> End Sequencing Supported by the linear structure of memory After the PC is incremented, the instruction fetched is the the next one in a linear sequence A normal termination occurs when the HALT instruction is fetched and executed

If <condition> Begin <statement 1> … <statement n> End Selection Selection (one-way if) statements use two types of instructions A comparison A conditional jump

Comparisons Require two operands (example, X > Y) The COMPARE opcode 0111 compares the data in the memory cell at the given address to the contents of the data register R The result of the comparison is deposited in the condition code register CCR

The Condition Code Register Comparison State of CCR CON(X) > R CON(X) = R CON(X) < R 1 1 1 CON(X) means contents of memory cell at address X

Example: Compare X and Y IR 1 1 1 1 1 1 Y X R 1 1 CCR 1 X = Y RAM 000000011001 1 1

Example: Compare X and Y IR 1 1 1 1 1 1 Y X R 1 1 CCR 1 X > Y RAM 000000011001 1

Example: Compare X and Y IR 1 1 1 1 1 1 Y X R 1 1 CCR 1 X < Y RAM 000000011001 1

Steps Required Comparisons require two steps: Load the second operand into register R Compare to the first operand (a memory address) LOAD Y COMPARE X

JUMP Instructions The JUMP instructions check the condition code and transfer control to the instruction at location X if the code is set in a certain way. Binary opcode Operation CCR 1000 JUMP X Any value 1001 JUMPGT X 100 1010 JUMPEQ X 010 1011 JUMPLT X 001 1100 JUMPNEQ X Any value but 010

Example If Statement High-level pseudocode Low-level pseudocode // Absolute value If X < 0 Set X to -X // Absolute value 1. LOAD ZERO 2. COMPARE X 3. JUMPGT LINE 6 4. SUBTRACT X 5. STORE X 6. Rest of code These two lines are skipped if X > 0

In Machine Code LOAD 000000000000 1 COMPARE 000000000001 1 1 1 1 1 1 1 COMPARE 000000000001 1 1 1 1 1 1 JUMPGT 000000000010 1 1 1 1 SUBTRACT 000000000011 1 1 1 1 1 STORE 000000000100 1 1 1 1 OUT 000000000101 1 1 1 1 1 1 HALT 000000000110 1 1 1 1 X 000000000111 1 1 1 ZERO 000000001000

If/Else and Loops Comparisons and jumps are also used for if/else statements and loops Typically use two jumps, one conditional and the other unconditional

Example: Output Sum of 1 .. 10 Set sum to 0 Set count to 1 While count <= 10 do Set sum to sum + count Increment count Output sum 1 clear sum 2 load one 3 store count 4 load count 5 compare eleven 6 jumpeq line 12 8 add sum 9 store sum 10 increment count 11 jump line 4 12 out sum 13 halt

Example: Output Sum of 1 .. 10 1 clear sum 2 load one 3 store count 4 load count 5 compare eleven 6 jumpeq line 12 8 add sum 9 store sum 10 increment count 11 jump line 4 12 out sum 13 halt 000000000000 1101 000000001111 000000000001 0000 000000001101 000000000010 0001 000000010000 000000000011 0000 000000010000 000000000100 0111 000000011110 000000000101 1010 000000001010 000000000110 0011 000000001111 000000000111 0001 000000001111 000000001000 0100 000000010000 000000001001 1000 000000000011 000000001010 1110 000000001111 000000001011 1111 000000000000 000000001100 0000 000000000000 (zero) 000000001101 0000 000000000001 (one) 000000001110 0000 000000001011 (eleven) 000000001111 0000 000000000000 (sum) 000000010000 0000 000000000000 (count)