COSC 121 PROJECT Overview Overview Text file compilation

  • Slides: 25
Download presentation
COSC 121 PROJECT

COSC 121 PROJECT

Overview

Overview

Overview Text file compilation Executable (byte code) Execute (run) Application running

Overview Text file compilation Executable (byte code) Execute (run) Application running

Overview b. P a L : I I t r Pa 5 N ATIO

Overview b. P a L : I I t r Pa 5 N ATIO L I P M O C Part I: L ab P 1 t o P 4 SIMULA TION

COSC 121 Project - Part I (Labs P 1 to P 4) CPU Simulation

COSC 121 Project - Part I (Labs P 1 to P 4) CPU Simulation

CPU Simulation Memory 0 Input 1 2 Program Counter Stores the address of the

CPU Simulation Memory 0 Input 1 2 Program Counter Stores the address of the next instruction Instruction Register Stores the instruction to execute Accumulator Used to store temporary calculations . . . CPU 99 Output

The memory Memory 0 Program 1 2 Instruction . . . Variables 99 Operation

The memory Memory 0 Program 1 2 Instruction . . . Variables 99 Operation Code Operand Value between 0 and 11. Value between 0 and 99. Each code corresponds to a specific instruction corresponds to a specific memory address

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1 2 LD STO ACC Memory[Operand] ACC 3 ADD ACC + Memory[Operand] 4 SUB ACC - Memory[Operand] 5 MPY ACC * Memory[Operand] 6 DIV ACC / Memory[Operand] 7 IN Display on screen a question mark. Wait for value. Memory[Operand] keyboard value 8 OUT Display OUTPUT = Memory[Operand] 9 B PC Operand 10 BG If ACC > 0 Then PC Operand 11 BZ If ACC = 0 Then PC Operand

Instructions Operation Code 0 Keyword in Action to Execute Language STOP Stop program 1

Instructions Operation Code 0 Keyword in Action to Execute Language STOP Stop program 1 LD Memory 0 ACC Memory[Operand] Input 1 01 99 Program Counter 2. Instruction Register LOAD OPERAND . Accumulator . 99 CPU 63 63 Output ACC Memory[99]

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1 2 LD STO Memory 0 ACC Memory[Operand] ACC Input 1 Program Counter 2. Instruction Register . 25 STORE OPERAND 25 . 99 02 99 CPU 63 Output Memory[99] ACC

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1 2 LD STO ACC Memory[Operand] ACC 3 ADD ACC + Memory[Operand] Memory 0 Input 1 Program Counter 2. Instruction Register . 88 ADD OPERAND 25 . 99 03 99 CPU 63 Output ACC + Memory[99]

Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1 2

Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1 2 LD STO ACC Memory[Operand] ACC 3 ADD ACC + Memory[Operand] 4 SUB ACC - Memory[Operand] Memory 0 Input 1 Program Counter 2. Instruction Register . 78 04 98 SUB OPERAND 88 . 98 10 99 63 CPU Output ACC - Memory[98]

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1 2 LD STO ACC Memory[Operand] ACC 3 ADD ACC + Memory[Operand] 4 SUB ACC - Memory[Operand] 5 MPY ACC * Memory[Operand] 6 DIV ACC / Memory[Operand] 7 IN Display on screen a question mark. Wait for value. Memory[Operand] keyboard value

Memory Input 0 07 98 IN OPERAND 1 Program Counter 2. Instruction Register .

Memory Input 0 07 98 IN OPERAND 1 Program Counter 2. Instruction Register . 78 . 98 CPU 10 99 63 Display ? Memory[98] keyboard entry Output ? 45 45

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1 2 LD STO ACC Memory[Operand] ACC 3 ADD ACC + Memory[Operand] 4 SUB ACC - Memory[Operand] 5 MPY ACC * Memory[Operand] 6 DIV ACC / Memory[Operand] 7 IN Display on screen a question mark. Wait for value. Memory[Operand] keyboard value 8 OUT Display OUTPUT = Memory[Operand]

Memory Input 0 1 08 99 OUT OPERAND Program Counter 2. Instruction Register .

Memory Input 0 1 08 99 OUT OPERAND Program Counter 2. Instruction Register . 78 . 98 10 99 63 CPU Output Display OUTPUT = Memory[99] OUTPUT = 63

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1 2 LD STO ACC Memory[Operand] ACC 3 ADD ACC + Memory[Operand] 4 SUB ACC - Memory[Operand] 5 MPY ACC * Memory[Operand] 6 DIV ACC / Memory[Operand] 7 IN Display on screen a question mark. Wait for value. Memory[Operand] keyboard value 8 OUT Display OUTPUT = Memory[Operand] 9 B PC Operand 10 BG If ACC > 0 Then PC Operand 11 BZ If ACC = 0 Then PC Operand

Memory 0 09 10 02 11 02 B BG BZ OPERAND If ACC =

Memory 0 09 10 02 11 02 B BG BZ OPERAND If ACC = >0 PC Operand 1 Input 2 5 2. Instruction Register . -10 78 . 98 10 99 63 CPU Output

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1

Instructions Instruction Keyword in Action to Execute Code Language 0 STOP Stop program 1 2 LD STO ACC Memory[Operand] ACC 3 ADD ACC + Memory[Operand] 4 SUB ACC - Memory[Operand] 5 MPY ACC * Memory[Operand] 6 DIV ACC / Memory[Operand] 7 IN Display on screen a question mark. Wait for value. Memory[Operand] keyboard value 8 OUT Display OUTPUT = Memory[Operand] 9 B PC Operand 10 BG If ACC > 0 Then PC Operand 11 BZ If ACC = 0 Then PC Operand

CPU Simulation Fetch Execute the instruction Execute Fetch the next instruction to execute Increment

CPU Simulation Fetch Execute the instruction Execute Fetch the next instruction to execute Increment program counter

Memory 0 0799 1 0798 2 0198 3 0499 4 1008 5 1108 6

Memory 0 0799 1 0798 2 0198 3 0499 4 1008 5 1108 6 0899 7 0909 8 0898 9 0000 Execute Input Increment PC Program 10 76318 029 54 Counter Instruction Register 0198 0798 0499 1008 0899 0000 0909 1108 0799 10 43 99 63 59 IR Memory[PC] 04 07 10 09 08 00 11 01 || 99 98 08 99 00 09 ACC Accumulator 43 -16 … 98 PC + 1 IR CPU 10 Fetch OUOperand PCIf ACC Stop >= 509 Then ? T 54 P 93 UT= PC Operand ACC ACC – Memory[Operand] Output

Memory 0 0799 1 0798 2 0198 3 0499 4 1008 5 1108 6

Memory 0 0799 1 0798 2 0198 3 0499 4 1008 5 1108 6 0899 7 0909 8 0898 9 0000 Execute Input Increment PC Program 9 8 054310 Counter 12 Instruction Register 0198 0799 0798 0499 1008 0898 0000 10 43 99 63 13 IR Memory[PC] 08 00 04 00 07 10 01 || 99 98 99 08 ACC Accumulator 43 30 … 98 PC + 1 IR CPU 10 Fetch Output OUTPUT = 43 If ACC ? 41>3 0 Then Stop PC Operand ACC ACC – Memory[Operand]

How to program that? ? ? Memory 0 Input 1 2 Program Counter .

How to program that? ? ? Memory 0 Input 1 2 Program Counter . . Instruction Register . Accumulator CPU 99 Output

Class Instance Variable(s) Methods Memory int[] storage get. Value. At(location) set. Value. At(location) load.

Class Instance Variable(s) Methods Memory int[] storage get. Value. At(location) set. Value. At(location) load. Program() Program. Counter int value get. Value() set. Value() increment. PC() Instruction. Register int value set. Value() get. Op. Code() get. Operand() Accumulator int value get. Value() set. Value() add(), subtract(), multiply(), divide() Terminal Computer input() output(value) Memory ram Program. Counter pc Instruction. Register ir Accumulator acc Terminal run()

Home Assignment Check Connect

Home Assignment Check Connect