CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
-
Upload
rosamond-potter -
Category
Documents
-
view
217 -
download
0
Transcript of CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
![Page 1: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/1.jpg)
CMSC 150PROGRAM EXECUTION
CS 150: Wed 1 Feb 2012
![Page 2: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/2.jpg)
Stored Program Concept
CPU
ALU control unit
…
registers
127
128
129
130
131
132
01010010
133
134...
……
01010110
01110010
11010010
10110010
10111110
11100000
00000001
01010010
11100000
![Page 3: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/3.jpg)
Our Example ArchitectureMainMemory
…
![Page 4: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/4.jpg)
Our Example Architecture…
MainMemory
00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
Address
![Page 5: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/5.jpg)
Our Example ArchitectureMainMemory
00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
InstructionRegister
Program CounterRegister
Data Register
Central Processing Unit
…Address
![Page 6: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/6.jpg)
Our Machine LanguageAssembly Language Instruction
Machine Language Instruction
CopyFrom 000
CopyTo 001
Add 010
Subtract 011
Read 100
Print 101
IfNegGoTo 110
Stop 111
![Page 7: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/7.jpg)
Our Hypothetical ComputerMainMemory
InstructionRegister
Program CounterRegister
Data Register
CPU
…
![Page 8: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/8.jpg)
Our Hypothetical ComputerMainMemory
InstructionRegister
Program CounterRegister
Data Register
CPU
• Word size: 8 bits (1 byte)…
![Page 9: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/9.jpg)
Our Hypothetical ComputerMainMemory
InstructionRegister
Program CounterRegister
Data Register
CPU
• Word size: 8 bits (1 byte)• Number of instructions: 8
…
![Page 10: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/10.jpg)
Our Hypothetical ComputerMainMemory
InstructionRegister
Program CounterRegister
Data Register
CPU
• Word size: 8 bits (1 byte)• Number of instructions: 8
To represent 23 = 8 total instructions, need 3 bits
…
![Page 11: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/11.jpg)
Our Hypothetical ComputerMainMemory
InstructionRegister
Program CounterRegister
Data Register
CPU
• 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
…
![Page 12: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/12.jpg)
Our Hypothetical ComputerMainMemory
00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
11110
11111
InstructionRegister
Program CounterRegister
Data Register
CPU
• 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
…
![Page 13: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/13.jpg)
Our Hypothetical ComputerMainMemory
00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
11110
11111
InstructionRegister
Program CounterRegister
Data Register
CPU
• 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
…
![Page 14: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/14.jpg)
Our Hypothetical ComputerMainMemory
00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
11110
11111
InstructionRegister
Program CounterRegister
Data Register
CPU
• 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
…
![Page 15: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/15.jpg)
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 = +1110001011 = -11
![Page 16: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/16.jpg)
Eight Machine Language InstructionsInstruction
CodeMeaning of the Instruction
000 Copy word from memory address into DR
001 Copy word to memory address from DR
010 Add word in memory address to word in DR
011 Subtract word in memory address from word in DR
100 Read word from input into DR
101 Print word in DR to output
110Conditional execution : If word in DR is negative, copy a new memory address into PC
111 Stop execution
Underline: an argument (value) required by that instruction
![Page 17: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/17.jpg)
Example of an Instruction
00110110 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
one word (here, one byte)
![Page 18: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/18.jpg)
Example of an Instruction
00110110 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Instruction code
![Page 19: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/19.jpg)
Example of an Instruction
00110110 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Argument(memory address)
![Page 20: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/20.jpg)
Example of an Instruction
00110110 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Decoding the Instruction:
![Page 21: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/21.jpg)
Example of an Instruction
00110110 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Decoding the Instruction:
Copy to …
![Page 22: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/22.jpg)
Example of an Instruction
00110110 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Decoding the Instruction:
Copy to …
![Page 23: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/23.jpg)
Example of an Instruction
00110110 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Decoding the Instruction:
Copy to address 10110…
![Page 24: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/24.jpg)
Example of an Instruction
00110110 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Decoding the Instruction:
Copy to address 10110 from DR
This instruction copies thecontents of the data registerinto memory cell addressed101102 = 2210
![Page 25: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/25.jpg)
Example of an Instruction
10000000 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Decoding the Instruction:
Read from input…
![Page 26: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/26.jpg)
Example of an Instruction
10000000 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Decoding the Instruction:
Read from input…
No argument…
![Page 27: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/27.jpg)
Example of an Instruction
10000000 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Decoding the Instruction:
Read from input…
No argument,hence zeros(to fill the byte)
![Page 28: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/28.jpg)
Example of an Instruction
10000000 Code Meaning of the Instruction
000 Copy from address into DR
001 Copy to address from DR
010 Add word in address to DR
011 Subtract word in address from DR
100 Read from input into DR
101 Print to output from DR
110 If DR is < 0, copy address into PC
111 Stop execution
Decoding the Instruction:
Read from input into DR
This instruction copies aword from the input unitinto the data register
![Page 29: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/29.jpg)
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
![Page 30: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/30.jpg)
Fetch-Execute Cycle
1. Copy the word referred to by the PC into the IR (i.e., fetch)
2. Increment the address stored in the PC
3. Decode & execute the contents of the IR
4. Unless a stop instruction, goto step 1
![Page 31: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/31.jpg)
00000 00001001 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister
ProgramCounter
00000
DataRegister
Input Unit Output Unit
Initial state of memory after loading program and setting PC to 00000
1
ExecutableProgram
![Page 32: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/32.jpg)
00000 00001001 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister
ProgramCounter
00000
DataRegister
Input Unit Output Unit
1. Copy word referred to by PC into Instruction Register
2
![Page 33: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/33.jpg)
00000 00001001 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister
ProgramCounter
00000
DataRegister
Input Unit Output Unit
1. Copy word referred to by PC into Instruction Register
3
![Page 34: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/34.jpg)
00000 00001001 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001001
ProgramCounter
00000
DataRegister
Input Unit Output Unit
1. Copy word referred to by PC into Instruction Register
4
![Page 35: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/35.jpg)
00000 00001001 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001001
ProgramCounter
00001
DataRegister
Input Unit Output Unit
2. Increment the Program Counter
5
![Page 36: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/36.jpg)
00000 00001001 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001001
ProgramCounter
00001
DataRegister
Input Unit Output Unit
3. Decode and Execute instruction
6
![Page 37: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/37.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001001
ProgramCounter
00001
DataRegister
Input Unit Output Unit
3. Decode and Execute instruction – 000 is op code for CopyFrom
7
![Page 38: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/38.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001001
ProgramCounter
00001
DataRegister
Input Unit Output Unit
3. Decode and Execute instruction – 01001 is address to copy from
8
![Page 39: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/39.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001001
ProgramCounter
00001
DataRegister
Input Unit Output Unit
3. Decode and Execute instruction – 01001 contains a word
9
![Page 40: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/40.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001001
ProgramCounter
00001
DataRegister10000001
Input Unit Output Unit
3. Decode and Execute instruction – Instruction execution is complete
10
![Page 41: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/41.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001001
ProgramCounter
00001
DataRegister10000001
Input Unit Output Unit
Repeat: 1. Copy word referred to by PC to IR
11
![Page 42: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/42.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11000101
ProgramCounter
00001
DataRegister10000001
Input Unit Output Unit
Repeat: 1. Copy word referred to by PC to IR
12
![Page 43: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/43.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11000101
ProgramCounter
00010
DataRegister10000001
Input Unit Output Unit
2. Increment PC
13
![Page 44: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/44.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11000101
ProgramCounter
00010
DataRegister10000001
Input Unit Output Unit
3. Decode and execute instruction
14
![Page 45: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/45.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11000101
ProgramCounter
00010
DataRegister10000001
Input Unit Output Unit
3. Decode and execute instruction – 110 is the op code for IfNegGoTo
15
![Page 46: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/46.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11000101
ProgramCounter
00010
DataRegister10000001
Input Unit Output Unit
3. Decode and execute instruction – Check value in data register
16
![Page 47: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/47.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11000101
ProgramCounter
00010
DataRegister10000001
Input Unit Output Unit
3. Decode and execute instruction – DR value is -1
17
![Page 48: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/48.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11000101
ProgramCounter
00010
DataRegister10000001
Input Unit Output Unit
3. Decode and execute instruction – Copy rightmost 5 bits of IR to PC
18
![Page 49: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/49.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11000101
ProgramCounter
00101
DataRegister10000001
Input Unit Output Unit
3. Decode and execute instruction – execution is complete
19
![Page 50: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/50.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11000101
ProgramCounter
00101
DataRegister10000001
Input Unit Output Unit
1. Copy word referred to by PC to IR
20
![Page 51: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/51.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001010
ProgramCounter
00101
DataRegister10000001
Input Unit Output Unit
1. Copy word referred to by PC to IR
21
![Page 52: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/52.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001010
ProgramCounter
00110
DataRegister10000001
Input Unit Output Unit
2. Increment PC
22
![Page 53: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/53.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001010
ProgramCounter
00110
DataRegister10000001
Input Unit Output Unit
3. Decode and execute instruction
23
![Page 54: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/54.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001010
ProgramCounter
00110
DataRegister10000001
Input Unit Output Unit
3. Decode and execute instruction – 000 is op code for CopyFrom
24
![Page 55: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/55.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001010
ProgramCounter
00110
DataRegister10000001
Input Unit Output Unit
3. Decode and execute instruction
25
![Page 56: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/56.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001010
ProgramCounter
00110
DataRegister00000110
Input Unit Output Unit
3. Decode and execute instruction – copy value to DR. Execution complete.
26
![Page 57: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/57.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00001010
ProgramCounter
00110
DataRegister00000110
Input Unit Output Unit
1. Copy word referred to by PC to IR.
27
![Page 58: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/58.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister01101100
ProgramCounter
00110
DataRegister00000110
Input Unit Output Unit
1. Copy word referred to by PC to IR.
28
![Page 59: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/59.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister01101100
ProgramCounter
00111
DataRegister00000110
Input Unit Output Unit
2. Increment PC
29
![Page 60: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/60.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister01101100
ProgramCounter
00111
DataRegister00000110
Input Unit Output Unit
3. Decode and execute instruction
30
![Page 61: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/61.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister01101100
ProgramCounter
00111
DataRegister00000110
Input Unit Output Unit
3. Decode and execute instruction – 011 is Subtract
31
![Page 62: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/62.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister01101100
ProgramCounter
00111
DataRegister00000110
Input Unit Output Unit
3. Decode and execute instruction – data register is first operand
32
![Page 63: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/63.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister01101100
ProgramCounter
00111
DataRegister00000110
Input Unit Output Unit
3. Decode and execute instruction – word at 01100 is second operand
34
![Page 64: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/64.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister01101100
ProgramCounter
00111
DataRegister00000110
Input Unit Output Unit
3. Decode and execute instruction – word at 01100 is second operand
35
![Page 65: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/65.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister01101100
ProgramCounter
00111
DataRegister00000110
Input Unit Output Unit
3. Decode and execute instruction: (610 – 110) = 510 = 000001012.
36
![Page 66: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/66.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister01101100
ProgramCounter
00111
DataRegister00000101
Input Unit Output Unit
3. Decode and execute instruction: 510 = 000001012. Result is stored in DR.
38
![Page 67: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/67.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister01101100
ProgramCounter
00111
DataRegister00000101
Input Unit Output Unit
1. Copy word referred to by PC to IR.
39
![Page 68: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/68.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00101010
ProgramCounter
00111
DataRegister00000101
Input Unit Output Unit
1. Copy word referred to by PC to IR.
40
![Page 69: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/69.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00101010
ProgramCounter
01000
DataRegister00000101
Input Unit Output Unit
2. Increment PC
41
![Page 70: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/70.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00101010
ProgramCounter
01000
DataRegister00000101
Input Unit Output Unit
3. Decode and execute instruction
42
![Page 71: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/71.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 CopyTo 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00101010
ProgramCounter
01000
DataRegister00000101
Input Unit Output Unit
3. Decode and execute instruction – 001 is CopyTo
43
![Page 72: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/72.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 CopyTo 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000110 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00101010
ProgramCounter
01000
DataRegister00000101
Input Unit Output Unit
3. Decode and execute instruction – 01010 is target location
44
![Page 73: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/73.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 CopyTo 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000101 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00101010
ProgramCounter
01000
DataRegister00000101
Input Unit Output Unit
3. Decode and execute instruction – value in DR copied to memory
45
![Page 74: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/74.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 CopyTo 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000101 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister00101010
ProgramCounter
01000
DataRegister00000101
Input Unit Output Unit
1. Copy word referred to by PC to IR
46
![Page 75: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/75.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 CopyTo 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000101 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11100000
ProgramCounter
01000
DataRegister00000101
Input Unit Output Unit
1. Copy word referred to by PC to IR
47
![Page 76: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/76.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 CopyTo 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000101 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11100000
ProgramCounter
01001
DataRegister00000101
Input Unit Output Unit
2. Increment PC
48
![Page 77: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/77.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 CopyTo 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000101 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11100000
ProgramCounter
01001
DataRegister00000101
Input Unit Output Unit
3. Decode and execute instruction
49
![Page 78: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/78.jpg)
00000 00001001 CopyFrom 10000 00000000
00001 11000101 IfNegGoTo 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 CopyFrom 10101 00000000
00110 01101100 Subtract 10110 00000000
00111 00101010 CopyTo 10111 00000000
01000 11100000 Stop 11000 00000000
01001 10000001 11001 00000000
01010 00000101 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11100000
ProgramCounter
01001
DataRegister00000101
Input Unit Output Unit
3. Decode and execute instruction – 111 is op code for Stop
50
![Page 79: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/79.jpg)
00000 00001001 10000 00000000
00001 11000101 10001 00000000
00010 00001010 10010 00000000
00011 01001011 10011 00000000
00100 11100000 10100 00000000
00101 00001010 10101 00000000
00110 01101100 10110 00000000
00111 00101010 10111 00000000
01000 11100000 11000 00000000
01001 10000001 11001 00000000
01010 00000101 11010 00000000
01011 00000100 11011 00000000
01100 00000001 11100 00000000
01101 00000000 11101 00000000
01110 00000000 11110 00000000
01111 00000000 11111 00000000
Main MemoryCPU
InstructionRegister11100000
ProgramCounter
01001
DataRegister00000101
Input Unit Output Unit
Stored Program Concept: Instructions & data together in main memory
50
Instructions
Data
CPU “knows” difference based only on execution process
![Page 80: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/80.jpg)
public static void main( String[] args ){
Random generator = new Random( 8675309 );
Scanner keyboard = new Scanner( System.in );
int value = keyboard.nextInt();String text = keyboard.next();
value += generator.nextInt( 100 );
System.out.println( text + ": " + value );
} Java executes instructions one-at-a-time in order
relates to fetch-execute cycle Each Java instruction may be multiple ML instructions
![Page 81: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/81.jpg)
Possible Overflow
Using our 1-byte word limit and sign magnitude, add the numbers:
011001102 + 000110112
![Page 82: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/82.jpg)
Possible Overflow
Using our 1-byte word limit and sign magnitude, add the numbers:
011001102 + 000110112
= 10210 + 2710 = 12910
= 100000012
![Page 83: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/83.jpg)
Possible Overflow
Using our 1-byte word limit and sign magnitude, add the numbers:
011001102 + 000110112
= 10210 + 2710 = 12910
= 100000012
sign bit (indicating negative)
![Page 84: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/84.jpg)
Possible Overflow
Using our 1-byte word limit and sign magnitude, add the numbers:
So computer would report -1 as the answer!
Overflow: too few bits to represent the result
011001102 + 000110112
= 10210 + 2710 = 12910
= 100000012
![Page 85: CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.](https://reader030.fdocuments.us/reader030/viewer/2022032722/56649f455503460f94c664df/html5/thumbnails/85.jpg)
00001001
11000101
00001010
01001011
11100000
00001010
01101100
00101010
11100000
10000001
00000110
00000100
00000001