Download presentation
1
CPU, Stored-Program Concept, Program Execution
CSC-255 Lecture 5 CPU, Stored-Program Concept, Program Execution (Covers Brookshear Chapter 2) Modified by Ufuk Verun from Jim Janossy © 2002, DePaul University CTI – Chicago and Brookshear © 2003 Pearson Education, Inc. CSC /703 - CTI/DePaul
2
Resources This PowerPoint presentation is available for download at Texbook: Chapter 2, Appendix C A Simple Machine Simulator: Print slides at 6 slides/page, avoid waste! Exams are based on slide content, homework and assigned readings CSC /703 - CTI/DePaul
3
Algorithmic Machine Must be able to:
Manipulate stored data Perform operations on data Coordinate sequence of operations Central Processing Unit (CPU) does it (in general) CSC /703 - CTI/DePaul
4
Basic Computer Components Overview
Central Processing Unit (CPU ) Memory (RAM – Random Access Memory) CPU and RAM are installed on the main circuit board (motherboard) CPU and RAM communicate on bus Disk drive, motherboard, power supply There are also devices such as graphics adaptor card, network interface card (NIC), sound card, etc. CSC /703 - CTI/DePaul
5
Computer Components Diagram
CSC /703 - CTI/DePaul
6
Memory-Mapped Input/Output
CSC /703 - CTI/DePaul
7
Central Processing Unit
ALU CU CSC /703 - CTI/DePaul
8
Registers Similar to memory cells, but with a lot faster access time
Located as part of the CPU There is no bus transfer to access the register Usually limited number of registers CPU has a limited capacity for components, therefore cannot pack so many registers Usually 8, 16, or more (depending on the architecture) CSC /703 - CTI/DePaul
9
Registers… Temporary holding place for data being manipulated by the CPU and ALU operations In most architectures, ALU is not allowed to manipulate data directly in memory cells Data in memory needs to be moved to a register first There are two types of registers: Special purpose (Program Counter -– PC, Instruction Register –- IR) General purpose (e.g., R0, R1, R2, …) CSC /703 - CTI/DePaul
10
Example: CPU/Registers and Main Memory
Example from Appendix C in Textbook CSC /703 - CTI/DePaul
11
Memory Usage Facts Registers hold data immediately applicable to an operation Cache holds recently used memory RAM holds data needed soon External storage (“mass storage”, such as hard disk) holds data and instructions not needed immediately Price decreases, capacity increases CSC /703 - CTI/DePaul
12
Control Unit Transfers data from memory to register
Tells ALU when and which register has data Activates logic circuits in ALU Tells ALU which register to put result in Transfers data from register to memory (if asked) Speed is usually measured in MIPs (millions of instructions per second) CSC /703 - CTI/DePaul
13
Bus Connects CPU, memory, disk, and other components
CPU can access data through the bus by specifying the memory cell address Usually 16 or 32 bits “wide” (parallel bit transfer, not serial one-at-a-time) Bus Speed (bits/sec) may differ from CPU speed Some architectures support multiple buses CSC /703 - CTI/DePaul
14
Example Algorithm: Add Contents of Two Memory Cells
CSC /703 - CTI/DePaul
15
Machine Instruction Types
Just a few instructions are sufficient for basic operations Three main categories: Data transfer Arithmetic/Logic Control Each instruction type is represented by a bit pattern CSC /703 - CTI/DePaul
16
Machine Instruction Format
Example from Appendix C in textbook CSC /703 - CTI/DePaul
17
Instruction Decoding Example from Appendix C in textbook
CSC /703 - CTI/DePaul
18
Instruction Decoding…
Example from Appendix C in textbook CSC /703 - CTI/DePaul
19
Machine Architectures vs Instruction Set
Reduced Instruction Set Computer (RISC) Relatively few basic instructions only Complex instructions have to be implemented by using basic instructions Complex Instruction Set Computer (CISC) Large number of instructions Instructions provided for complex tasks as well as simple tasks Both used in practice RISC: Motorola/IBM PowerPC, Sun SPARC CISC: Intel CSC /703 - CTI/DePaul
20
Data Transfer Instructions
Instructions associated with the transfer of data, such as: LOAD register,address Copy bit pattern from memory cell (specified by address) to register STORE register,address Copy bit pattern from register to memory cell (specified by address) MOVE register1,register2 Copy bit pattern from register1 to register2 CSC /703 - CTI/DePaul
21
Arithmetic/Logic Instructions
Instructions associated with the arithmetic and logical manipulation of data in CPU registers, such as: ADD, SUBTRACT NEGATE (Two’s complement negation) AND, OR, XOR SHIFT, ROTATE Usually involves one or more registers CSC /703 - CTI/DePaul
22
AND. . . Example: CSC /703 - CTI/DePaul
23
OR. . . Example: CSC /703 - CTI/DePaul
24
XOR. . . Example: CSC /703 - CTI/DePaul
25
Bit-Oriented Instructions
AND, OR, XOR are useful in testing or changing single bits or collections of bits within a byte These operations common in communications or port-setting tasks Involve use of a mask or pattern and an input byte CSC /703 - CTI/DePaul
26
AND with a Mask 0 0 0 0 1 1 1 1 (mask) 1 0 1 0 1 0 1 0 (input)
(result) Mask can be used to zero out or hide any desired part of a byte CSC /703 - CTI/DePaul
27
AND in a Bit Test 0 0 0 0 1 0 0 0 (mask) 1 0 1 0 1 0 1 0 (input)
(result) Is bit 5 (from left) set to 1 in the input? AND with mask then check to see if the result is = CSC /703 - CTI/DePaul
28
AND to Turn Off a Bit 1 1 1 1 0 1 1 1 (mask) 1 0 1 0 1 0 1 0 (input)
(result) Modifying a bit in a byte is possible by using AND with the appropriate mask CSC /703 - CTI/DePaul
29
OR to Turn On a Bit 0 0 0 1 0 0 0 0 (mask) 1 0 1 0 1 0 1 0 (input)
(result) Modifying a bit in a byte is possible by using OR with the appropriate mask CSC /703 - CTI/DePaul
30
XOR to Complement 1 1 1 1 1 1 1 1 (mask) 1 0 1 0 1 0 1 0 (input)
(result) XOR with a mask of all 1’s produces the complement of the input bit pattern CSC /703 - CTI/DePaul
31
XOR to Get a Number’s Two’s Complement
(mask) (input) (result) XOR with a mask of all 1’s produces the complement of the input bit pattern Add 1 to complement of input pattern: + Two’s complement of input CSC /703 - CTI/DePaul
32
Right Logical Shift 1 0 1 0 1 0 1 1 Input pattern
Right shift instruction 0 is fed from left The rightmost 1 is lost Output pattern CSC /703 - CTI/DePaul
33
Right Circular Logical Shift
Input pattern Right shift instruction The rightmost bit moves to leftmost Output pattern CSC /703 - CTI/DePaul
34
Rotate Bit Pattern to Right
CSC /703 - CTI/DePaul
35
Shift Definitions Circular shifts are also called rotations
Two types of shifts: left and right Logical shifts lose bits at end moved to Circular shifts circulate bits to front Arithmetic shifts preserve sign bit (don’t involve it in shifts), the most significant bit CSC /703 - CTI/DePaul
36
Control Instructions Instructions associated with program flow control, such as: GO address JUMP address SKIP address GOIF - “GO IF (condition)” address STOP, HALT, QUIT CSC /703 - CTI/DePaul
37
Stored-Program Concept
Von-Neumann machine Program is in memory cells like data Control unit extracts instructions from memory, decodes, executes Machine language is in bit patterns Chapter 2 and Appendix C in textbook describe a simulator CSC /703 - CTI/DePaul
38
Programs vs. Data There is no difference in appearance between programs and data Both are stored as 0’s and 1’s Both are housed in memory Who keeps track of what is what? Answer: you (the programmer) must CSC /703 - CTI/DePaul
39
Program Execution Control Unit handles it
Program Counter contains memory cell address of next instruction Instruction Register contains the current instruction (the instruction now being executed) CSC /703 - CTI/DePaul
40
Machine Cycle Fetch Decode Execute
Bring next instruction from memory to CU Increment the program counter (depending on how many bytes the instruction has) Decode Interpret instruction in instruction register Execute Activate appropriate circuitry for instruction CSC /703 - CTI/DePaul
41
Machine Cycle CSC /703 - CTI/DePaul
42
Machine Cycle Timing Controlled by an oscillator called “clock”
Clock ticks at a very fast rate (such as 1.8GHz) Circuits in CU that actually Fetch, Decode, Execute are triggered by clock Each instruction execution might take one or more clock cycles to complete Depends on how complicated the instruction is CSC /703 - CTI/DePaul
43
General Program Startup
Program counter is initialized to 0 (points to first memory cell as place to get next instruction) Fetch brings instruction in cell 0 (the one that is currently referenced by the program Counter) to instruction register in CU Program execution starts and continues until a termination instruction (such as halt) is reached CSC /703 - CTI/DePaul
44
How to Handle Jump (Branch/Go/Skip) Instruction?
Branching instruction is interesting Basic form: jmp address All it does is put the address contained in the instruction into the Program Counter On next machine cycle, Fetch gets the instruction in the cell that the Program Counter points to CSC /703 - CTI/DePaul
45
Simple Machine Simulator
Implements the machine architecture described in Brookshear Appendix C Adds a few more instructions: jumpLE,jumpEQ Supports storing data items: db Anything written to register RF is displayed on output window Supports labeling a location in code (useful for handling relocation of instructions during program edits and for jumps) Executable program is also available on Course Online (SimpSim.exe) Get this program and experiment with it to understand the basics Check the help pages and instruction formats/examples CSC /703 - CTI/DePaul
46
Simple Machine Simulator
Refer to the screen of SimpSim for the architecture description based on Appendix C and how to use the simulator There are some example programs: simpleadd.asm asciiout.asm hello.asm multiply_1.asm multiply_2.asm divide.asm CSC /703 - CTI/DePaul
47
Example: Simple Addition Program (simpleadd.asm)
; Simple Addition Example... ; ; CSC255 - CTI/DePaul ; Ufuk Verun ; This program adds the contents of two memory cells X and Y, and ; stores the result in memory cell Z. ; A: Contents of memory cell X ; B: Contents of memory cell Y ; At the end, result=A+B is stored in memory cell Z. load R1,[X] ;Load contents of memory cell X (A) into R1 load R2,[Y] ;Load contents of memory cell Y (B) into R2 addi R1,R1,R2 ;Calculate R1=A+B store R1,[Z] ;Store the result of A+B in memory cell Z halt X: db ;X is the memory address that contains 10 Y: db ;Y is the memory address that contains 20 Z: db ;Z is the memory address that holds result CSC /703 - CTI/DePaul
48
Example: ASCIIOut Program (asciiout.asm)
; ASCII Output Example... ; load RF, ; Initialize to 0 load R7, ; Increment NextChar:addi RF,RF,R7 ; Increase (is written to ; RF(=screen)) jmp NextChar ; Repeat Assembled code: 00: 2F 00 02: 04: 5FF7 06: B004 CSC /703 - CTI/DePaul
49
Example: HelloWorld Program (hello.asm)
; Hello World Example... ; ; CSC255 - CTI/DePaul ; Ufuk Verun ; This program displays a Hello World message and smiling faces... load R1,Message ; The start of the string load R2, ; Increment step load R0, ; 0 is used to identify string-terminator NextChar:load RF,[R1] ; Get character and print it on screen addi R1,R1,R2 ; Increase address jmpEQ RF=R0,Ready ; When string-terminator, then ready jmp NextChar ; Next character Ready: halt Message: db ,10,10 db ,32,32,32,1,32,2,32,1,32,2,32,1,10 db " Hello World !!",10 db ,32,32,32,1,32,2,32,1,32,2,32,1 db ; String-terminator CSC /703 - CTI/DePaul
50
More Examples: divide.asm multiply_1.asm, multiply_2.asm
The following additional examples are available on Course Online Make sure you understand how each one works multiply_1.asm, multiply_2.asm ; There is no multiply instruction in the architecture of Appendix C. ; This program calculates A*B by repetitive additions. ; Result is calculated by adding A B times and keeping the running result ; in register R4. ; At the end of the program, the result is stored in register R4. divide.asm ; There is no divide instruction in the architecture of Appendix C. ; This program calculates A/B by repetitive subtractions, where A and B ; are positive integers within range (in two's complement using ; 8 bits). ; Result is calculated by subtracting B from A (as long as we can without ; going negative) ; Quotient is found by counting how many times we subtracted. ; At the end, the quotient is stored in R3, the remainder is stored in R4. ; Example: ; for A=10, B=3, we need to store R3=3, R4=1 at the end. CSC /703 - CTI/DePaul
51
Multiple Programs in Memory
Several programs can be in memory at the same time Running a program just means setting the Program Counter to point to the cell with the program’s first instruction The operating system (for example Windows XP) manages memory management and processing of programs CSC /703 - CTI/DePaul
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.