A Level Computer Science Topic 5: Computer Architecture and Assembly

Slides:



Advertisements
Similar presentations
GCSE Computing Lesson 5.
Advertisements

Chapter 2 Machine Language.
The Little man computer
Processor Technology and Architecture
Chapter 4 Processor Technology and Architecture. Chapter goals Describe CPU instruction and execution cycles Explain how primitive CPU instructions are.
Dale & Lewis Chapter 5 Computing components. Let’s design a computer Generic CPU with registers −Program counter (PC) – 5 bits (size of addresses) −Instruction.
The CPU The Central Presentation Unit Language Levels Fetch execute cycle Processor speed.
An Interactive Web-Based Simulation of a General Computer Architecture
Basic Microcomputer Design. Inside the CPU Registers – storage locations Control Unit (CU) – coordinates the sequencing of steps involved in executing.
Writer:-Rashedul Hasan Editor:- Jasim Uddin
Internal hardware and external components of a computer Three-box Model  Processor The brain of the system Executes programs A big finite state machine.
CS 1308 Computer Literacy and the Internet Computer Systems Organization.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Chapter 8: The Very Simple Computer
Model Computer CPU Arithmetic Logic Unit Control Unit Memory Unit
General Concepts of Computer Organization Overview of Microcomputer.
Computer Architecture And Organization UNIT-II General System Architecture.
Computer Organization CSC 405 (VSC) Very Simple Computer.
Computer Architecture Memory, Math and Logic. Basic Building Blocks Seen: – Memory – Logic & Math.
Little Man Computer When your program gets “translated to machine code” all 0’s & 1’s The translator must know the language of the program (java) as well.
© GCSE Computing Candidates should be able to:  describe the characteristics of an assembler Slide 1.
Dale & Lewis Chapter 5 Computing components
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/09/29
Session 4 Teaching Computing to GCSE Level with Python.
CBP 2002ITY 270 Computer Architecture1 Module Structure Whirlwind Review – Fetch-Execute Simulation Instruction Set Architectures RISC vs x86 How to build.
The Processor & its components. The CPU The brain. Performs all major calculations. Controls and manages the operations of other components of the computer.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Computer Operation. Binary Codes CPU operates in binary codes Representation of values in binary codes Instructions to CPU in binary codes Addresses in.
CPU (Central Processing Unit). The CPU is the brain of the computer. Sometimes referred to simply as the processor or central processor, the CPU is where.
What’s going on here? Can you think of a generic way to describe both of these?
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Stored Program Concept Learning Objectives Learn the meaning of the stored program concept The processor and its components The fetch-decode-execute and.
OCR GCSE Computer Science Teaching and Learning Resources
The Little man computer
Chapter 10: Computer systems (1)
Computer Organization
ECE 103 Engineering Programming Chapter 5 Programming Languages
Control Unit Lecture 6.
Central Processing Unit Architecture
A Closer Look at Instruction Set Architectures
William Stallings Computer Organization and Architecture 8th Edition
Edexcel GCSE Computer Science Topic 15 - The Processor (CPU)
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
Lesson Objectives A note about notes: Aims
The Central Processing Unit
Introduction to Computer Architecture
Assembly Language for Intel-Based Computers, 5th Edition
Chapter 1: An Overview of Computers and Programming Languages
Computer Architecture
Instructions at the Lowest Level
Starter Read the Feedback Click on Add new Feedback Open Realsmart
Teaching Computing to GCSE
Computer Science 210 Computer Organization
System Architecture 1 Chapter 2.
The Processor and Machine Language
Computer Science 210 Computer Organization
CSCE Fall 2013 Prof. Jennifer L. Welch.
Computer Structure S.Abinash 11/29/ _02.
COMP 1321 Digital Infrastructure
Making Programming Friendlier
CPU Key Revision Points.
The Little Man Computer
Chapter 1 Introduction.
Computer Architecture
Computer Architecture
CSCE Fall 2012 Prof. Jennifer L. Welch.
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/09/29
Chapter 4 The Von Neumann Model
Little Man Computer.
Presentation transcript:

A Level Computer Science Topic 5: Computer Architecture and Assembly Teaching London Computing A Level Computer Science Topic 5: Computer Architecture and Assembly William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London

Aims Understand CPU structure in more detail Fetch-execute cycle Faster CPUs Write simple assembly code Use Little Man Computer Understand principles of compiling Compare compilers and interpreters

CPU Structure What’s in a CPU

Simple Computer Processor Memory addresses data I/O data CPU Data Program instructions I/O Keyboard Display Disk Memory addresses data CPU data Keyboard I/F Disk I/F Display I/F

Memory data Each location Two interfaces address has an address hold a value Two interfaces address – which location? data – what value? address

Registers (or Accumulators) A storage area inside the CPU VERY FAST Used for arguments and results to one calculation step data Register – 1 memory location Read register Write to register Control lines

CPU Structure Accumulators Data PC Instruction Address ALU Accumulators Data for calculation Data Word to/from memory PC Address of next instruction Instruction Address For memory access Accumulators ALU data Data Control Unit Program Counter Instruction memory address Address Control Unit

Instructions OpCode Address Instruction Instructions for arithmetic What to do: Opcode Where: memory address Instructions for arithmetic Add, Multiply, Subtract Memory instructions LOAD value from memory STORE value in memory

Add Instruction Add Address One address and accumulator (ACC) Value at address added to accumulator ACC = ACC + Memory[Address]

A Simulator for a Simple CPU Little Man Computer A Simulator for a Simple CPU

Advantages of LMC Very simple Number of implementations Java applet Excel Flash, .net MacOS Some incompatibilities Feature: uses decimal not binary

LMC CPU Structure Visible registers shown in red data memory ALU Accumulator ALU data MEM Data Control Unit Program Counter Instruction memory address Mem Address Control Unit

Memory locations Program counter Accumulator

Excel LMC Windows .net LMC Flash LMC

Feature Comparison Step and Animation Can program using mnemonics Most allow single stepping – see fetch-execute Animation – e.g. flash version Can program using mnemonics LDA, STA, ADD … Supported in e.g. applet Not supported in Excel, Flash versions Programming versus demonstration

LMC Instructions

Instructions OpCode Address Opcode: 1 decimal digit Address: two decimal digits – xx Code Mnemonic Description 000 HLT Halt 1xx ADD Add: acc + memory  acc 2xx SUB Subtract: acc – memory  acc 3xx STA Store: acc  memory 5xx LDA Load: memory  acc 6xx BR Branch always 7xx BRZ Branch is acc zero 8xx BRP Branch if acc > 0 901 IN Input 902 OUT Output

Add and Subtract Instruction Address SUB Address One address and accumulator (ACC) Value at address combined with accumulator value Accumulator changed Add: ACC  ACC + Memory[Address] Subtract: ACC  ACC – Memory[Address]

Load and Store Instruction LDA Address STA Address Move data between memory and accumulator (ACC) Load: ACC  Memory[Address] Store: Memory[Address]  ACC

Branch Instructions BR Address Changes program counter May depend on accumulator (ACC) value BR: PC  Address BRZ: if ACC == 0 then PC  Address BRP: if ACC > 0 then PC  Address

Practical Exercises 1.1 Enter the program for example 1.1 Understand how to Enter Assemble / compile Run the program See notes on available versions.

LMC Example

Compiling a Simple Program Compiler translates high level program to low level E.g. x = y + z LDA y ADD z STA x HLT x y z

Running the Simple Program PC LDA y ADD z IR LDA STA x HLT ACC 17 x y 17 z 9

Running the Simple Program PC LDA y ADD z IR ADD STA x HLT ACC 26 17 x y 17 z 9

Running the Simple Program PC LDA y ADD z IR STA STA x HLT ACC 26 x 26 y 17 z 9

Running the Simple Program PC LDA y ADD z IR HLT STA x HLT ACC 26 x 26 y 17 z 9

Practical Exercises 1.3-1.7 Try any of the challenge problems 1.3 to 1.7 1.4 onwards require the use of branch instructions If statements Loops See notes for examples

How the Computer Processes Instructions Fetch-Execute Cycle How the Computer Processes Instructions

Fetch-Execute Each instruction cycle consists on two subcycles Fetch cycle Load the next instruction (Opcode + address) Use Program Counter Execute cycle Control unit interprets the opcode ... an operation to be executed on the data by the ALU Fetch next instruction Decode & execute instruction Start Halt

Fetch Instruction Program counter to address register Read memory at address Memory data to ‘Data’ ‘Data’ to instruction register Advance program counter ALU Accumulators ALU 3 data Data Control Unit 4 Program Counter Instruction memory 1 address Address Control Unit 2

Execute Instruction Decode instruction Address from instruction to ‘address register’ Access memory Data from memory to ‘data register’ Add (e.g.) data and accumulator value Update accumulator ALU Accumulators 6 5 ALU 5 data 4 Data Control Unit 2 Program Counter Instruction memory 1 address Address Control Unit 3

Address of memory access Data to/from memory

Summary of CPU Architecture Memory contains data and program Program counter: address of next instruction Instructions represented in binary Each instruction has an ‘opcode’ Instructions contain addresses Addresses used to access data Computer does ‘fetch-execute’ ‘Execute’ depends on opcode Computer can be built from < 10,000 electronic switches (transistors)

Discussion Could we act out the way a computer works? Can you explain he key idea of the stored program computer simply? Should we be amazed at the working of a computer?

Practical Exercise 1.2 Review the fetch execute steps using LMC

Compilers and Interpreters

Compiler Compiler translates high level program to low level Compiled languages Statically typed Close to machine Examples: C, C++, (Java) Compiler for each CPU assembly code source code LDA y ADD z STA x HLT 11010101 10010111 01110100 10000000 x = y + z object code

Inside a Compiler CPU object code source code 11010101 10010111 01110100 10000000 Abstract syntax tree code generator x = y + z parser type checker Parser: checks that the source code matches the grammar Type checker: checks types of variables and expressions Code generator: generates (optimised) code

Principle of an Interpreter CPU-L CPU-X 11010101 10010111 01110100 x = y + z Rep of C Code (C) in language L Interpreter in X for L One machine can emulate another ‘micro-coded’ CPU Intel CPUs and RISC inside

Java and .NET Language Java is compiled to ‘byte code’ JVM Java is compiled to ‘byte code’ Byte code for Java ‘virtual machine’ (JVM) One compiler Libraries Other languages CPU Java code 11010101 10010111 01110100 Java compiler x = y + z byte code Byte code interpreter The JVM is emulated on real computers ‘JIT’ compiler

How Does an Interpreter Work? acc = 0 mdr = 0 mar = 0 pc = 0 memory = [504,105,306, 0, 11, 17,...] State of the LMC: registers and memory Example: LMC emulator def readMem(memory): global mdr mdr = memory[mar] def execute(memory, opcode, arg): global acc, mar, mdr, pc if opcode == ADD: mar = arg readMem(memory) acc = acc + mdr elif opcode == SUB: acc = acc – mdr ... Update state following rules def fetch(memory): global pc, mar mar = pc pc = pc + 1 readMem(memory)

Practical Exercise 1.2 What would the benefits be for your pupils in completing an exercise such as this?

Making a Faster Computer

Clock Steps in sequence are controlled by a clock Clock frequency 8086 – 10 MHz Pentium 4 – 3 GHz However, clock speeds no longer increasing much Processing power depends on Clock speed Clock cycles to execute an instruction

1GHz Clock 109 cycles per second Each instruction takes longer 1 cycle every 1 ns Light travels 1 m in approx 3 ns Billion instructions per second (up to) Each instruction takes longer … many instruction in process at once Memory access is slower 10 of ns

Moore’s Law http://www.intel.com/technology/mooreslaw/index.htm

Faster Computer Faster clocks More Registers; Bigger registers smaller IC lines (90  45  32  22nm) shorter time to switch More Registers; Bigger registers 32  64 bits Fetch-execute pipeline overlap the fetch and execute Cache memory Multiple cores

Intel 86 Family 8086 – 1978 80386 – 1986 Pentium 4 – 2000 16 bits 80386 – 1986 32 bits Pentium 4 – 2000 32 bits  64 bits Intel core i3, i5, i7 COMPATIBLE compiled program More instruction Longer words More on chip floating point cache memory Instructions in parallel pipeline superscalar multi-core

Summary A CPU executes Fetch-Execute One machine can emulator another Fetch: next instructions from memory Execute: data to/from memory and accumulator Opcode determines execute One machine can emulator another Program execution Compiler: translates Interpreter: parses then interprets Blend: Java or .NET and byte code