Wednesday, September 13, Chapter 4

Similar documents
Wednesday, February 4, Chapter 4

Chapter. Computer Architecture

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram:

Problem Set 1 Solutions

Wednesday, February 7, 2018

Computer Organization II CMSC 3833 Lecture 33

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

ASSEMBLY LANGUAGE MACHINE ORGANIZATION

Microcontroller Systems

Advanced Parallel Architecture Lesson 3. Annalisa Massini /2015

Digital System Design Using Verilog. - Processing Unit Design

Practical Malware Analysis

COSC 243. Computer Architecture 1. COSC 243 (Computer Architecture) Lecture 6 - Computer Architecture 1 1

CPU Structure and Function

Lecture1: introduction. Outline: History overview Central processing unite Register set Special purpose address registers Datapath Control unit

The MARIE Architecture

Advanced Parallel Architecture Lesson 3. Annalisa Massini /2015

Module 5 - CPU Design

Lecture 5: Computer Organization Instruction Execution. Computer Organization Block Diagram. Components. General Purpose Registers.


Mark II Aiken Relay Calculator

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

2.2 THE MARIE Instruction Set Architecture

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

Department of Computer and Mathematical Sciences. Lab 4: Introduction to MARIE

Chapter 3. Z80 Instructions & Assembly Language. Von Neumann Architecture. Memory. instructions. program. data

Menu Computer Organization Programming Model for the an example microprocessors (the G-CPU & Motorola 68HC11) Assembly Programming Look into my...

Harry H. Porter, 2006

Chapter 7 Central Processor Unit (S08CPUV2)

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

Computer Architecture (part 2)

Notes: The Marie Simulator

UNIT- 5. Chapter 12 Processor Structure and Function

CPU Structure and Function. Chapter 12, William Stallings Computer Organization and Architecture 7 th Edition

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

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

William Stallings Computer Organization and Architecture

A3 Computer Architecture

SCRAM Introduction. Philipp Koehn. 19 February 2018

Dec Hex Bin ORG ; ZERO. Introduction To Computing

What is an Addressing Mode?

Wednesday, September 6, 2017

Wednesday, January 28, 2018

Chapter 4. MARIE: An Introduction to a Simple Computer. Chapter 4 Objectives. 4.1 Introduction. 4.2 CPU Basics

Chapter 2 Instruction Set Architecture

CPU Structure and Function

2010 Summer Answers [OS I]

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

SISTEMI EMBEDDED. Basic Concepts about Computers. Federico Baronti Last version:

Chapter 4. MARIE: An Introduction to a Simple Computer

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Computer Organization and Technology Processor and System Structures

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

CMPUT101 Introduction to Computing - Summer 2002

Chapter 1. Microprocessor architecture ECE Dr. Mohamed Mahmoud.

DC57 COMPUTER ORGANIZATION JUNE 2013

1. INTRODUCTION TO MICROPROCESSOR AND MICROCOMPUTER ARCHITECTURE:

William Stallings Computer Organization and Architecture. Chapter 11 CPU Structure and Function

Wednesday, April 19, 2017

Copyright 2000 N. AYDIN. All rights reserved. 1

Memory Models. Registers

Processing Unit CS206T

IA-32 architecture. PDP8/e architecture Arithmetic. IA-32 architecture (cont)

COMPUTER SYSTEM. COMPUTER SYSTEM IB DP Computer science Standard Level ICS3U. COMPUTER SYSTEM IB DP Computer science Standard Level ICS3U

THE MICROPROCESSOR Von Neumann s Architecture Model

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

CPE300: Digital System Architecture and Design

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 12 Processor Structure and Function

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

Extra-credit QUIZ Pipelining -due next time-

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

AS/A Level Computing Syllabus 2011

17. Instruction Sets: Characteristics and Functions

MARIE: An Introduction to a Simple Computer

The PAW Architecture Reference Manual

COMPUTER ORGANIZATION & ARCHITECTURE

MARIE: An Introduction to a Simple Computer

Processor design - MIPS

Register Transfer and Micro-operations

11. A Computing Machine

COS 140: Foundations of Computer Science

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

COMPUTER ARCHITECTURE AND ORGANIZATION Register Transfer and Micro-operations 1. Introduction A digital system is an interconnection of digital

Introduction to Computer Science. Homework 1

Summary of Computer Architecture

CHAPTER SIX BASIC COMPUTER ORGANIZATION AND DESIGN

Computer Organization CS 206 T Lec# 2: Instruction Sets

Instruction : A command to the microprocessor to perform a given task on specified data. Each instruction has two parts

Introduction to MiniSim A Simple von Neumann Machine

COSC345 Software Engineering. Basic Computer Architecture and The Stack

Chapter 10 - Computer Arithmetic

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Data Paths and Microprogramming

The Stored Program Computer

8086 INTERNAL ARCHITECTURE

Assembly Language Design

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

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language

When an instruction is initially read from memory it goes to the Instruction register.

Designing Computers. The Von Neumann Architecture. The Von Neumann Architecture. The Von Neumann Architecture

CMPUT101 Introduction to Computing - Summer 2002

Transcription:

Wednesday, September 13, 2017 Topics for today Introduction to Computer Systems Static overview Operation Cycle Introduction to Pep/9 Features of the system Operational cycle Program trace Categories of instruction Example program Von Neumann bugs Chapter 4 Recall that we are looking at systems that use the stored program model of von Neumann. Warford (Fig. 4.1) presents an overview of a computer system having four main components: CPU (Central Processing Unit) Main memory Input/Output Secondary memory connected by both control and data lines. Some systems have memory-mapped input/output. Pep/9 is such a system where input and output devices can be accessed as if they were locations in memory. This memory-mapping is reflected in the diagram: Address Data Control CPU Secondary Memory Input Output Main Memory So, for example, if the CPU wants to read the data in memory location 24, it puts the number 24 on the address lines issues a Read-from-Memory signal on the control lines Comp 162 Notes Page 1 of 17 September 13, 2017

The contents of memory location 24 are then sent along the data lines to the CPU. Similarly to store the number 99 into memory location 150 the CPU puts the number 99 on the data lines puts 150 on the address lines issues a Write-to-Memory signal on the control lines Looking at a CPU component in more detail we can sub-divide it into two sections: Data Path Control. Data Path Control Unit Data Path The Data Path contains registers for local storage of data: the CPU can access these very quickly. A register is just an N-bit object. the Arithmetic and Logic Unit for performing operation on registers (we saw the ALU and its status bits earlier) The Control Unit The Control Unit sends control signals to the Data Path telling it what to do and when to do it. For example, certain control signals indicate which arithmetic or logical function the ALU should perform. The Control Unit gets feedback from the Data Path section, for example the values on the Status bits from the ALU. The Control unit typically contains a micromemory, clock and so on. We are not concerned with the functioning of the Control unit in this course; COMP 262 looks at how it works. The Data Path contains registers for storing data plus the Arithmetic and Logic Unit (ALU) for performing operations and appropriate connections between registers and the ALU. In the following diagram we identify registers that might exist (at least conceptually) in the Data Path. Comp 162 Notes Page 2 of 17 September 13, 2017

Address lines Data lines MAR MBR PC IR GP1 GPn Control lines ALU Status bits Abbreviation Register Name Purpose MAR Memory Address Register Terminator for address lines. Not normally directly accessible to programmers MBR Memory Buffer Register Terminator for data lines. Not normally directly accessible to programmers. PC Program Counter Holds address of next instruction to be executed. IR Instruction Register Holds the current instruction. Not normally directly accessible to programmers GP i General Purpose One or more registers for programmer use Comp 162 Notes Page 3 of 17 September 13, 2017

The size of some registers (MAR, MBR, PC) usually depend on properties of main memory: * The number of different memory addresses determines the size of the PC and the MAR because each of these registers holds a memory address. * The amount of data we can read from and write to memory at one time determines the size of the MBR because that is where the data is stored before/after a transfer. In Figure 4.2 Warford shows the registers accessible to programmers in his Pep/9 system. More on these later. So far we have just looked at the static structure of the machine. How does it run? Operation cycle Version 1.0 (generic) A top-level description of the CPU operation cycle is repeat { } fetch next instruction from memory decode it find out what kind of instruction it is execute it perform appropriate operations Operation cycle Version 2.0 (generic, more detail) The following pseudocode algorithm shows how the program starts and stops and also how various registers interact (see also Fig. 4.31) Initialize PC to the address of the first instruction of the program repeat { Put Memory[PC] into IR PC = PC + 1 Decode the current instruction (in IR) what does it do? Execute the current instruction } until IR = "Halt" The PC has to be incremented after we fetch an instruction otherwise we would fetch the same instruction over and over again. Comp 162 Notes Page 4 of 17 September 13, 2017

Operation cycle Version 2.1 (generic, a little more detail) Knowing about the functions of the registers we can expand Put Memory{PC] into IR Initialize PC to the address of the first instruction repeat { Put PC into MAR Issue memory read signal; wait until read complete Put MBR into IR PC = PC + 1 Decode the current instruction (IR) Execute the current instruction } until IR = "Halt" When we have looked at the Pep/9 architecture we will devise an operation cycle specifically for the Pep/9 machine. Comp 162 Notes Page 5 of 17 September 13, 2017

Pep/9 (Warford's Virtual Machine Environment) Memory (see Fig 4.3??!) Memory is 64K bytes. Only about 2% of this is reserved for the operating system. Memory is byte-addressable so addresses are 16 bits long (64K = 2 16.) Addresses range from 0..65535 (decimal) which is 0..FFFF in hex Two addresses (FC15 and FC16) represent input and output devices respectively A diagram of the memory (better than Fig 4.3 and Fig 4.4) is the following. Each addressable cell is an 8-bit byte. 0000 0001 0002 FC15 FC16 Input device Output device FFFE FFFF The Pep/9 CPU (Fig 4.2) The Pep/9 CPU has a status register holding NZVC (Negative, Zero, overflow and Carry) bits from the ALU. (We have seen that these bits are set as a side-effect of ALU operations.) only two general purpose registers: o Register A (accumulator) o Register X (index). Each register is 16 bits long. Real computers will usually have many more general purpose registers. For many purposes the two registers have the same properties but it turns out that Register X has additional uses that we will see later. stack pointer (SP). The stack is in important run-time structure in the memory. The SP register holds the address of the item at the top of the stack. Comp 162 Notes Page 6 of 17 September 13, 2017

Pep/9 instructions Instructions are either 1 byte or 3 bytes long (this means the Instruction Register is 24 bits long to hold the longest possible instruction. The first (possibly only) byte of an instruction * will contain The Opcode (operation code) This indicates what type of operation the instruction performs. It varies in size from 4 bits to 8 bits. Opcodes can be thought of as a variable-length code; they must be unambiguous so that this byte can only be decoded one way by the CPU. * may contain (depending on the nature of the instruction) A 1-bit register number (r) to indicate if using register A or register X A 3-bit addressing mode (aaa) or a 1-bit addressing mode (a) (3-byte instructions only) this indicates how to use the following 2 bytes). A 1-bit number (n) used for various purposes The second and third bytes of an instruction (if present) combine to form a 16-bit number that is used in various ways that we will see later. See Figure 4.6 for a list of machine code instructions for Pep/9. Pep/9 programs Pep/9 programs always occupy locations 0, 1, 2, in the memory and the instruction at location 0 is always the first one executed when the program runs. The following is therefore a Pep/9- specific operation cycle (see also Fig. 4.32) Comp 162 Notes Page 7 of 17 September 13, 2017

Operation cycle Version 3.0 (Pep/9 specific) pc = 0 Repeat { firstbyte = memory[pc] // opcode, maybe register and mode pc = pc + 1 if (a 3-byte instruction) // determined by opcode bits { get next 2 bytes: mem[pc], mem[pc+1] pc = pc + 2 form two bytes into 16-bit integer (N) } action = function (opcode, register, mode, N) } until opcode=stop With this algorithm and the list of instructions in Figure 4.6 we can trace a program to see what it does. Example Suppose the first 8 bytes of the Pep/9 memory are as follows Address Contents (hex) 0 C0 1 00 2 07 3 08 4 60 5 00 6 03 7 00 Here is how the program would run (note the updating of the PC) PC 0 Fetch byte 0 and update PC. In hex the byte is it is C0, in binary it is 11000000 1 Decode the instruction. The opcode byte must match uniquely with one of the patterns in Fig 4.6. In this case the match is with 1100 r aaa Load register r with a word from memory It is not a one-byte unary instruction so get the next two bytes (from addresses 1 and 2) and update the PC. These two bytes are the operand; in hex the operand is 0007 Comp 162 Notes Page 8 of 17 September 13, 2017

3 Execute the instruction. Register is A (r=0). Operand is 0007. aaa=000 The aaa bits being 000 indicates that the 0007 is the operand of the instruction (rather than, for example, the address of the operand). So this instruction loads the number 0007 into register A Register A 0 0 0 7 3 Fetch byte 3 and update PC. In binary the byte fetched (08) is 00001000 4 Decode the instruction. It is matches unary "negate register" 0000100r 4 Execute the instruction. Register is A (r=0). So this instruction negates register A Register A F F F 9 4 Fetch byte 4 and update PC. In binary the byte fetched (60) is 01100000 5 Decode the instruction. It matches a 3-byte "add to register" 0111 r aaa It is not a unary instruction so we get bytes 5 and 6 (0003) and update the PC. 7 Execute the instruction. Register is A (r=0) Operand is 0003 aaa = 000 Operand is 0003 so Register A is now FFFC (FFF9 + 0003) Register A F F F C 7 Fetch byte 8 and update PC. In binary the byte fetched (00) is 000000000 Comp 162 Notes Page 9 of 17 September 13, 2017

8 Decode the instruction. It matches unary 00000000 = STOP 9 Execute the instruction stop the CPU Pep/9 users can enter either assembly code programs (discussed in Chapter 5) or programs in hexadecimal (Chapter 4). The former have to be assembled then loaded into the Pep/9 memory. The latter just need to be loaded. More on this later. The Pep/9 Instruction set Next: look at briefly at some of the instructions in the Pep/9 instruction set. There are 40 instructions in total. We can group them into 6 categories Category Number in this category Examples Stop 1 Stop Data movement 7 Load register from memory, store byte to memory Arithmetic/Logical 14 Add location to register, compare 2 bytes Input/Output 4 Output hexadecimal integer, input decimal number Flow of Control 12 Branch if overflow Other 2 No operation Category 1: Stop/Halt instructions Every instruction set needs one instruction that stops the CPU. In Pep/9 the STOP instruction is opcode 00000000. (Pep/9 is a virtual environment so when the Pep/9 program terminates, it just returns control to the user window.) 00000000 is a good choice for the opcode for the STOP instruction. Many architectures use 00...00 for the STOP/HALT instruction. This is because if the user forgets to include STOP in the program it will continue to execute memory locations but will probably soon encounter one containing zero and stop. Comp 162 Notes Page 10 of 17 September 13, 2017

Category 2: Data movement The user program (instructions and data) is in main memory but the circuits that perform arithmetic operations are in the CPU. They take inputs from registers and return results to registers. Thus we need instructions that move data between main memory and the CPU registers. In general, at the machine level, "load" = copy data from memory to a CPU register - see example program above "store" = copy data from a CPU register to memory. In each case the movement is only a copy operation like an assignment statement in a highlevel language - the source operand is left unchanged. Prior data in the destination location is overwritten. Computers like Pep/9 that have relatively few different instructions typically do not have instructions that move data from memory-to-memory (these are less common now anyway for efficiency reasons). There are only three Pep/9 instructions that move data from one register to another: MOVSPA MOVFLGA MOVAFLG and none of them is used much. Example data movement instructions. Suppose we have the following (hex) values in memory: and Register A contains Address Contents 0016 23 0017 5F 0018 1C 0019 55 001A 47 001B 32 46 1A The instruction Load Register A with Word from 18 results in Register A changing to 1C 55 Comp 162 Notes Page 11 of 17 September 13, 2017

Note: (1) Old data in Register A is overwritten (2) Pep/9 is a "big-endian" machine - in a multi-byte data object, such as the 16-bit word in the example above, the most significant part is stored in the lowest address. On a "little-endian" machine it is the other way round, Register A would be 551C. (3) In the Pep/9 system we can treat any pair of adjacent memory locations as a word; this is not necessarily true on all real computers. Pep/9 has instructions (such as the one above) for moving words (16-bit objects) and bytes (8-bit objects). Usually we deal with words because registers are 16 bits long. Load byte and store byte instructions move bytes. They operate on the least significant half of a register leaving the most significant half unchanged. So if we follow the instruction above by Load Register A with Byte from 17 then Register A changes to 1C 5F Status bits - we will see later that many instructions affect the 4 status bits N,Z,V,C and that this is useful in creating "if" and "while" constructions. The "Load" instruction, for example, will set N if the number loaded is negative and set Z if the number loaded is zero. Category 3: Arithmetic and Logical Instructions ADD/SUB. Pep/9 has no multiply and divide instructions. If we have time later in the course we will look at register-based multiplication and division algorithms; we can do better than repeated addition/subtraction. ADD and SUB may set any of the status bits. AND/OR - logical operations. Doesn't make sense for them to affect V or C bits. SHIFT - in addition to Arithmetic Shift Right/Left (roughly equivalent to divide/multiply by 2) there are "rotate" instructions that perform circular shifts. In Pep/9, the circular shift includes the carry bit, see p. 274. NOT/NEGATE - note the difference between these two. The former is a logical operation, the latter is arithmetic. The former gives you the one's complement, the latter gives you the two's complement. Category 4: Input/Output In Pep/9, input/output is memory mapped. Conceptually, two memory locations are permanently attached to character input/output devices: FC15 to input and FC16 to output. Comp 162 Notes Page 12 of 17 September 13, 2017

To output a character, we write it to MEM[FC16]. Whenever we read from MEM[FC15] we get the next character entered as input by the user. At the assembly code level there are four higher-order instructions that let us, without worrying about the detailed conversions, input a decimal integer output a decimal integer output a string output a hexadecimal number. We will see later how these four instructions are handled by the Operating System. Category 5: Flow of Control There are instructions that alter the flow of control so we are not limited to programs that begin at location 0 and proceed sequentially until a STOP instruction. Some of the instructions use the status bits to determine whether to transfer control to a particular location. There are also instructions that implement a simple function/subroutine mechanism. More on this when we get to Chapter 5. There is redundancy in this category, the number of instructions could be reduced without affecting our ability to implement algorithms. Category 6: Other Sometimes it is useful to have an instruction (NOP) that does nothing makes no change to memory, registers or status bits. We can use such an instruction to overwrite code and effectively delete that code without having to modify other instructions in the program. Pep/9 also allows us to modify the operating system to cause the NOP opcodes to do something more useful. von Neumann "bugs" In Fig. 4.33 is a simple program that outputs "Hi". Q. What would happen if the programmer forgot the STOP instruction? A. The program would crash after outputting Hi Q. Why? A. It would attempt to execute byte 48 as an instruction and 48 is one of the relatively few numbers that is not a valid opcode byte. Comp 162 Notes Page 13 of 17 September 13, 2017

Because a program s instructions and data are stored in the same memory, it is possible to execute a data location as an instruction this is sometime done accidentally if we forget to include a STOP/HALT instruction in our program (see example above) or put it in the wrong place.. to treat an instruction as data. We may wish to do this deliberately see later. However, it is not considered good programming practice. (1) Data as instruction In the following program, the programmer put STOP in the wrong place. The translation is When the program runs ldwa 0xFFFF,I ; load all 1s anda 6,d ; now AND with 1200 (stored at location 6).word 0x1200 stop ; this should be before the data not after.end Location Contents 0 C0 1 FF 2 FF 3 81 4 00 5 06 6 12 7 00 8 00 It executes C0 FF FF ; loads register A with all 1 s Then 81 00 06 ; ANDs with the contents of location 6 ( 1200) Then 12 00 00 ; the data and the following byte 120000 is interpreted as the instruction BR 0 ; branch (jump) to location 0 so the program branches back to location 0 and loops forever. Comp 162 Notes Page 14 of 17 September 13, 2017

(2) Instruction as data See Fig 4.37 where the first two instructions of the program change an ADD instruction (opcode 91) to a SUB instruction (opcode 71). Reading The binary/hex level is covered in chapter 4, you can skim step-by-step details of how particular instructions work. Chapter 5. This covers the basic properties of the Pep/9 assembly language. Programming assignments will be in assembly language and not hexadecimal! Comp 162 Notes Page 15 of 17 September 13, 2017

Review Questions 1. Determine, from Fig. 4.41 or otherwise, the largest number of bytes that a user program can occupy. 2. Suppose that, because of the data structures in a program, the number of bytes available for instructions in a Pep/9 program is 48000. (a) how many instructions can we have if they are all 1-byte long? (b) how many instructions can we have if they are all 3-bytes long? (c) how many instructions can we have if half are 1-byte and half are 3-byte? 3. Pep-9¾ is a computer with 4 registers and instructions that are all 8-bits long. Some instructions specify two registers: some specify one register : and some do not specify any register: ooooxxyy ooooooxx oooooooo Given that there are instructions of all three types, what is the largest number of 2-register instructions that we can have? 4. Following on from question 3, if there are M 2-register instructions, what is the largest number of 1-register instructions we can have? 5. In the Pep/9 system, negating what number) sets the overflow flag? Comp 162 Notes Page 16 of 17 September 13, 2017

Review Answers 1. Address FB8E is the base of the run-time stack (see Fig. 4.41) so programs can be in locations 0..FB8E. In decimal, FB8E is 64398 decimal so the number of bytes is 64399. 2. (a) 48000 (b) 16000 (c).5x*1 +.5X*3 = 48000. X = 24000. 3. 15. E.g., opcodes 0000 to 1110. Opcode 1111 is reserved as prefix for longer opcodes. 4. (16-M)*4 1. For each unused 4-bit opcode, we can attach 2 bits (4-combinations) but remember to leave one pattern unused to be the start of the 0-register instructions. 5. 0x8000. This is -32768. The negative of this is 32768 which is outside the 16-bit range. Comp 162 Notes Page 17 of 17 September 13, 2017