850 likes | 981 Views
CMSC 150 program execution. CS 150: Wed 1 Feb 2012. Stored Program Concept. 01010010. 127. 128. 01010110. 129. 01110010. CPU. 130. 11010010. 10110010. 131. registers. …. 132. 10111110. 133. 11100000. 134. 00000001. ALU. control unit. …. 01010010.
E N D
CMSC 150program execution CS 150: Wed 1 Feb 2012
Stored Program Concept 01010010 127 128 01010110 129 01110010 CPU 130 11010010 10110010 131 registers … 132 10111110 133 11100000 134 00000001 ALU control unit . . . … 01010010 11100000 …
Our Example Architecture Main Memory …
Our Example Architecture Main Memory Address 00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 …
Our Example Architecture Main Memory Address 00000 Central Processing Unit 00001 00010 Instruction Register Program Counter Register 00011 00100 00101 00110 00111 Data Register 01000 01001 …
Our Hypothetical Computer Main Memory CPU Instruction Register Program Counter Register … Data Register
Our Hypothetical Computer Main Memory • Word size: 8 bits (1 byte) CPU Instruction Register Program Counter Register … Data Register
Our Hypothetical Computer Main Memory • Word size: 8 bits (1 byte) • Number of instructions: 8 CPU Instruction Register Program Counter Register … Data Register
Our Hypothetical Computer Main Memory • Word size: 8 bits (1 byte) • Number of instructions: 8 • To represent 23 = 8 total instructions, need 3 bits CPU Instruction Register Program Counter Register … Data Register
Our Hypothetical Computer Main Memory • Word size: 8 bits (1 byte) • Number of instructions: 8 • To represent 23 = 8 total instructions, need 3 bits • Leaves 5 bits to represent addresses CPU Instruction Register Program Counter Register … Data Register
Our Hypothetical Computer Main Memory • Word size: 8 bits (1 byte) • Number of instructions: 8 • To represent 23 = 8 total instructions, need 3 bits • Leaves 5 bits to represent addresses • 5 bits for addresses: 25 = 32 memory cells 00000 00001 00010 00011 00100 00101 CPU 00110 Instruction Register Program Counter Register 00111 01000 01001 … Data Register 11110 11111
Our Hypothetical Computer Main Memory • Word size: 8 bits (1 byte) • Number of instructions: 8 • To represent 23 = 8 total instructions, need 3 bits • Leaves 5 bits to represent addresses • 5 bits for addresses: 25 = 32 memory cells 00000 00001 00010 00011 00100 00101 CPU 00110 Instruction Register Program Counter Register 00111 01000 01001 … Data Register 11110 11111
Our Hypothetical Computer Main Memory • Word size: 8 bits (1 byte) • Number of instructions: 8 • To represent 23 = 8 total instructions, need 3 bits • Leaves 5 bits to represent addresses • 5 bits for addresses: 25 = 32 memory cells 00000 00001 00010 00011 00100 00101 CPU 00110 Instruction Register Program Counter Register 00111 01000 01001 … Data Register 11110 11111
Data In Our Computer • Use sign-magnitude to represent integers • 8 bits for data • leftmost bit will be sign (0: non-neg; 1: neg) • 7 remaining bits: magnitude in binary 00001011 = +11 10001011 = -11
Eight Machine Language Instructions Underline: an argument (value) required by that instruction
Example of an Instruction 00110110 one word (here, one byte)
Example of an Instruction 00110110 Instruction code
Example of an Instruction 00110110 Argument (memory address)
Example of an Instruction 00110110 Decoding the Instruction:
Example of an Instruction 00110110 Decoding the Instruction: Copy to …
Example of an Instruction 00110110 Decoding the Instruction: Copy to …
Example of an Instruction 00110110 Decoding the Instruction: Copy to address 10110…
Example of an Instruction 00110110 Decoding the Instruction: Copy to address 10110 from DR This instruction copies the contents of the data register into memory cell addressed 101102 = 2210
Example of an Instruction 10000000 Decoding the Instruction: Read from input…
Example of an Instruction 10000000 Decoding the Instruction: Read from input… No argument…
Example of an Instruction 10000000 Decoding the Instruction: Read from input… No argument, hence zeros (to fill the byte)
Example of an Instruction 10000000 Decoding the Instruction: Read from input into DR This instruction copies a word from the input unit into the data register
Preparing To Execute a Program • Your program is first written in a high-level language (e.g., Java): source code • Converted into machine language:executable • To run, executable is copied into main memory • PC is loaded with the memory address of the first instruction in the executable
Fetch-Execute Cycle • Copy the word referred to by the PC into the IR (i.e., fetch) • Increment the address stored in the PC • Decode & execute the contents of the IR • Unless a stop instruction, goto step 1
1 CPU Main Memory Program Counter Instruction Register Data Register Executable Program Input Unit Output Unit Initial state of memory after loading program and setting PC to 00000
2 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 1. Copy word referred to by PC into Instruction Register
3 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 1. Copy word referred to by PC into Instruction Register
4 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 1. Copy word referred to by PC into Instruction Register
5 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 2. Increment the Program Counter
6 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and Execute instruction
7 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and Execute instruction – 000 is op code for CopyFrom
8 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and Execute instruction – 01001 is address to copy from
9 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and Execute instruction – 01001 contains a word
10 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and Execute instruction – Instruction execution is complete
11 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit Repeat: 1. Copy word referred to by PC to IR
12 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit Repeat: 1. Copy word referred to by PC to IR
13 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 2. Increment PC
14 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and execute instruction
15 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and execute instruction – 110 is the op code for IfNegGoTo
16 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and execute instruction – Check value in data register
17 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and execute instruction – DR value is -1
18 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and execute instruction – Copy rightmost 5 bits of IR to PC
19 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 3. Decode and execute instruction – execution is complete
20 CPU Main Memory Program Counter Instruction Register Data Register Input Unit Output Unit 1. Copy word referred to by PC to IR