61
Program Execution

Program Execution

  • Upload
    raine

  • View
    36

  • Download
    0

Embed Size (px)

DESCRIPTION

Program Execution. Preparation. The assembly language version is assembled into a machine language executable The executable is copied into main memory The Program Counter Register is loaded with the address of the first instruction in the program. Woody's instruction cycle. - PowerPoint PPT Presentation

Citation preview

Page 1: Program Execution

Program Execution

Page 2: Program Execution

Preparation

The assembly language version is assembled into a machine language executable

The executable is copied into main memory

The Program Counter Register is loaded with the address of the first instruction in the program

Page 3: Program Execution

Woody's instruction cycle

1. Copy the word referred to by the Program Counter into the Instruction Register

2. Add 1 to the address in the Program Counter

3. Decode and execute the contents of the Instruction Register

Page 4: Program Execution

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

00000000

ProgramCounter

00000

DataRegister

00000000

Input Unit Output Unit

Initial state of memory after loading program and setting PC to 00000

1

Page 5: Program Execution

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

00000000

ProgramCounter

00000

DataRegister

00000000

Input Unit Output Unit

1. Copy word referred to by PC into Instruction register

2

Page 6: Program Execution

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

00000000

ProgramCounter

00000

DataRegister

00000000

Input Unit Output Unit

1. Copy word referred to by PC into Instruction register

3

Page 7: Program Execution

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

00001001

ProgramCounter

00000

DataRegister

00000000

Input Unit Output Unit

1. Copy word referred to by PC into Instruction register

4

Page 8: Program Execution

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

00001001

ProgramCounter

00001

DataRegister

00000000

Input Unit Output Unit

2. Add 1 to the Program Counter

5

Page 9: Program Execution

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

00001001

ProgramCounter

00001

DataRegister

00000000

Input Unit Output Unit

3. Decode and Execute instruction

6

Page 10: Program Execution

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

InstructionRegister

00001001

ProgramCounter

00001

DataRegister

00000000

Input Unit Output Unit

3. Decode and Execute instruction – 000 is op code for CopyFrom

7

Page 11: Program Execution

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

InstructionRegister

00001001

ProgramCounter

00001

DataRegister

00000000

Input Unit Output Unit

3. Decode and Execute instruction – 01001 is address to copy from

8

Page 12: Program Execution

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

InstructionRegister

00001001

ProgramCounter

00001

DataRegister

00000000

Input Unit Output Unit

3. Decode and Execute instruction – 01001 is address to copy from

9

Page 13: Program Execution

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

InstructionRegister

00001001

ProgramCounter

00001

DataRegister

10000001

Input Unit Output Unit

3. Decode and Execute instruction – Instruction execution is complete

10

Page 14: Program Execution

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

InstructionRegister

00001001

ProgramCounter

00001

DataRegister

10000001

Input Unit Output Unit

Repeat: 1. Copy word referred to by PC to IR

11

Page 15: Program Execution

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

InstructionRegister

11000101

ProgramCounter

00001

DataRegister

10000001

Input Unit Output Unit

Repeat: 1. Copy word referred to by PC to IR

12

Page 16: Program Execution

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

InstructionRegister

11000101

ProgramCounter

00010

DataRegister

10000001

Input Unit Output Unit

2. Add 1 to PC

13

Page 17: Program Execution

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

InstructionRegister

11000101

ProgramCounter

00010

DataRegister

10000001

Input Unit Output Unit

3. Decode and execute instruction

14

Page 18: Program Execution

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

InstructionRegister

11000101

ProgramCounter

00010

DataRegister

10000001

Input Unit Output Unit

3. Decode and execute instruction – 110 is the op code for IfNegGoTo

15

Page 19: Program Execution

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

InstructionRegister

11000101

ProgramCounter

00010

DataRegister

10000001

Input Unit Output Unit

3. Decode and execute instruction – Check value in data register

16

Page 20: Program Execution

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

InstructionRegister

11000101

ProgramCounter

00010

DataRegister

10000001

Input Unit Output Unit

3. Decode and execute instruction – DR value is -1

17

Page 21: Program Execution

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

InstructionRegister

11000101

ProgramCounter

00010

DataRegister

10000001

Input Unit Output Unit

3. Decode and execute instruction – Copy rightmost 5 bits of IR to PC

18

Page 22: Program Execution

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

InstructionRegister

11000101

ProgramCounter

00101

DataRegister

10000001

Input Unit Output Unit

3. Decode and execute instruction – execution is complete

19

Page 23: Program Execution

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

InstructionRegister

11000101

ProgramCounter

00101

DataRegister

10000001

Input Unit Output Unit

1. Copy word referred to by PC to IR

20

Page 24: Program Execution

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

InstructionRegister

00001010

ProgramCounter

00101

DataRegister

10000001

Input Unit Output Unit

1. Copy word referred to by PC to IR

21

Page 25: Program Execution

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

InstructionRegister

00001010

ProgramCounter

00110

DataRegister

10000001

Input Unit Output Unit

2. Add 1 to PC

22

Page 26: Program Execution

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

InstructionRegister

00001010

ProgramCounter

00110

DataRegister

10000001

Input Unit Output Unit

3. Decode and execute instruction

23

Page 27: Program Execution

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

InstructionRegister

00001010

ProgramCounter

00110

DataRegister

10000001

Input Unit Output Unit

3. Decode and execute instruction – 000 is op code for CopyFrom

24

Page 28: Program Execution

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

InstructionRegister

00001010

ProgramCounter

00110

DataRegister

10000001

Input Unit Output Unit

3. Decode and execute instruction

25

Page 29: Program Execution

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

InstructionRegister

00001010

ProgramCounter

00110

DataRegister

00000110

Input Unit Output Unit

3. Decode and execute instruction – copy value to DR. Execution complete.

26

Page 30: Program Execution

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

InstructionRegister

00001010

ProgramCounter

00110

DataRegister

00000110

Input Unit Output Unit

1. Copy word referred to by PC to IR.

27

Page 31: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00110

DataRegister

00000110

Input Unit Output Unit

1. Copy word referred to by PC to IR.

28

Page 32: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000110

Input Unit Output Unit

2. Add 1 to PC

29

Page 33: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000110

Input Unit Output Unit

3. Decode and execute instruction

30

Page 34: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000110

Input Unit Output Unit

3. Decode and execute instruction – 011 is Subtract

31

Page 35: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000110

Input Unit Output Unit

3. Decode and execute instruction – data register is first operand

32

Page 36: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000110

Input Unit Output Unit

3. Decode and execute instruction – data register is first operand

33

Page 37: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000110

Input Unit Output Unit

3. Decode and execute instruction – word at 01100 is second operand

34

Page 38: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000110

Input Unit Output Unit

3. Decode and execute instruction – word at 01100 is second operand

35

Page 39: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000110

Input Unit Output Unit

3. Decode and execute instruction: (6 – 1) = 5. Result is stored in DR.

36

Page 40: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000110

Input Unit Output Unit

3. Decode and execute instruction: (6 – 1) = 5. Result is stored in DR.

37

Page 41: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000101

Input Unit Output Unit

3. Decode and execute instruction: (6 – 1) = 5. Result is stored in DR.

38

Page 42: Program Execution

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

InstructionRegister

01101100

ProgramCounter

00111

DataRegister

00000101

Input Unit Output Unit

1. Copy word referred to by PC to IR.

39

Page 43: Program Execution

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

InstructionRegister

00101010

ProgramCounter

00111

DataRegister

00000101

Input Unit Output Unit

1. Copy word referred to by PC to IR.

40

Page 44: Program Execution

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

InstructionRegister

00101010

ProgramCounter

01000

DataRegister

00000101

Input Unit Output Unit

2. Add 1 to PC

41

Page 45: Program Execution

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

InstructionRegister

00101010

ProgramCounter

01000

DataRegister

00000101

Input Unit Output Unit

3. Decode and execute instruction

42

Page 46: Program Execution

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

InstructionRegister

00101010

ProgramCounter

01000

DataRegister

00000101

Input Unit Output Unit

3. Decode and execute instruction – 001 is CopyTo

43

Page 47: Program Execution

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

InstructionRegister

00101010

ProgramCounter

01000

DataRegister

00000101

Input Unit Output Unit

3. Decode and execute instruction – 01010 is target location

44

Page 48: Program Execution

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

InstructionRegister

00101010

ProgramCounter

01000

DataRegister

00000101

Input Unit Output Unit

3. Decode and execute instruction – value in DR copied to memory

45

Page 49: Program Execution

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

InstructionRegister

00101010

ProgramCounter

01000

DataRegister

00000101

Input Unit Output Unit

1. Copy word referred to by PC to IR

46

Page 50: Program Execution

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

InstructionRegister

11100000

ProgramCounter

01000

DataRegister

00000101

Input Unit Output Unit

1. Copy word referred to by PC to IR

47

Page 51: Program Execution

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

InstructionRegister

11100000

ProgramCounter

01001

DataRegister

00000101

Input Unit Output Unit

2. Add 1 to PC

48

Page 52: Program Execution

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

InstructionRegister

11100000

ProgramCounter

01001

DataRegister

00000101

Input Unit Output Unit

3. Decode and execute instruction

49

Page 53: Program Execution

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

InstructionRegister

11100000

ProgramCounter

01001

DataRegister

00000101

Input Unit Output Unit

3. Decode and execute instruction – 111 is op code for Stop

50

Page 54: Program Execution

Key points• Only programs for which the instructions

and data are in the appropriate machine language format can be executed by a computer.

• Assembly language substitutes meaningful names for instructions and conventional notation for numeric values

• Assembly language programs can be mechanically translated to machine language

Page 55: Program Execution

Is Assembly Language a "real" language?

Page 56: Program Execution

Is Assembly Language a "real" language?

• Computers don't understand the instructions or data used in AL programs

Page 57: Program Execution

Is Assembly Language a "real" language?

• Computers don't understand the instructions or data used in AL programs

• Assembly language is a useful abstraction that helps humans interact with the computer.

Page 58: Program Execution

Is Assembly Language a "real" language?

• Computers don't understand the instructions or data used in AL programs

• Assembly language is a useful abstraction that helps humans interact with the computer.

• The concept of memory locations is a useful abstraction for grids of transistors

Page 59: Program Execution

Is Assembly Language a "real" language?

• Computers don't understand the instructions or data used in AL programs

• Assembly language is a useful abstraction that helps humans interact with the computer.

• The concept of memory locations is a useful abstraction for grids of transistors

• Maps are useful abstractions of the physical world.

Page 60: Program Execution

The usefulness of computers is a direct result of the usefulness of the abstractions we have created for them.

Page 61: Program Execution

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 00000001 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

00000000

ProgramCounter

00000

DataRegister

00000000

Input Unit Output Unit

Exercise: trace the execution of this program.