Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve this problem in Java Problem Overview The project will simulate a simple computer system consisting of a CPU and Memory. The CPU and Memory

Solve this problem in Java

Problem Overview

The project will simulate a simple computer system consisting of a CPU and Memory. The CPU and Memory will be simulated by separate processes that communicate.

a. Processor interaction with main memory. b. Processor instruction behavior. c. Role of registers. d. Stack processing. e. Procedure calls.

f. System calls. g. Interrupt handling. h. Memory protection. i. I/O.

Problem Details

CPU It will have these registers: PC, SP, IR, AC, X, Y. It will support the instructions shown on the next page of this document. It will run the user program at address 0. Instructions are fetched into the IR from memory. The operand can be fetched into a local variable. Each instruction should be executed before the next instruction is fetched. The user stack resides at the end of user memory and grows down toward address 0. The system stack resides at the end of system memory and grows down toward address 0. There is no hardware enforcement of stack size. The program ends when the End instruction is executed. The 2 processes should end at that time. The user program cannot access system memory (exits with error message). Memory It will consist of 2000 integer entries, 0-999 for the user program, 1000-1999 for system code. It will support two operations: read(address) - returns the value at the address write(address, data) - writes the data to the address Memory will initialize itself by reading a program file.

Timer A timer will interrupt the processor after every X instructions, where X is a command-line parameter.

Interrupt processing There are two forms of interrupts: the timer and a system call using the int instruction. In both cases the CPU should enter kernel mode. The stack pointer should be switched to the system stack. SP and PC registers should be saved on the system stack. (The handler may save additional registers). A timer interrupt should cause execution at address 1000. The int instruction should cause execution at address 1500. Interrupts should be disabled during interrupt processing to avoid nested execution. The iret instruction returns from an interrupt.

Instruction set

1 = Load value 2 = Load addr 3 = LoadInd addr 4 = LoadIdxX addr 5 = LoadIdxY addr 6 = LoadSpX 7 = Store addr 8 = Get 9 = Put port

10 = AddX 11 = AddY 12 = SubX 13 = SubY 14 = CopyToX 15 = CopyFromX 16 = CopyToY 17 = CopyFromY 18 = CopyToSp 19 = CopyFromSp 20 = Jump addr 21 = JumpIfEqual addr 22 = JumpIfNotEqual addr 23 = Call addr 24 = Ret 25 = IncX 26 = DecX 27 = Push 28 = Pop 29 = Int 30 = IRet 50 = End Load the value into the AC Load the value at the address into the AC Load the value from the address found in the given address into the AC (for example, if LoadInd 500, and 500 contains 100, then load from 100). Load the value at (address+X) into the AC (for example, if LoadIdxX 500, and X contains 10, then load from 510). Load the value at (address+Y) into the AC Load from (Sp+X) into the AC (if SP is 990, and X is 1, load from 991). Store the value in the AC into the address Gets a random int from 1 to 100 into the AC If port=1, writes AC as an int to the screen If port=2, writes AC as a char to the screen Add the value in X to the AC Add the value in Y to the AC Subtract the value in X from the AC Subtract the value in Y from the AC Copy the value in the AC to X Copy the value in X to the AC Copy the value in the AC to Y Copy the value in Y to the AC Copy the value in AC to the SP Copy the value in SP to the AC Jump to the address Jump to the address only if the value in the AC is zero Jump to the address only if the value in the AC is not zero Push return address onto stack, jump to the address Pop return address from the stack, jump to the address Increment the value in X Decrement the value in X Push AC onto stack Pop from stack into AC Perform system call Return from system call End execution

Input File Format

Each instruction is on a separate line, with its operand (if any) on the following line. The instruction or operand may be followed by a comment which the loader will ignore. Anything following an integer is a comment, whether or not it begins with //. A line may be blank in which case the loader will skip it without advancing the load address. A line may begin by a period followed by a number which causes the loader to change the load address. Your program should run correctly with the any valid input files.

sample1.txt

1 // Load 0 0 14 // CopyToX 4 // LoadIdxX 32 (load from A-Z table) 32 21 // JumpIfEqual 12 12 9 // Put 2 (output as char) 2 25 // IncX 20 // Jump 3 3 1 // Load 0 0 16 // CopyToY 5 // LoadIdxY 59 (load from 1-10 table) 59 21 // JumpIfEqual 27 27 9 // Put 1 (output as int) 1 1 // Load 1 (because no IncY instruction) 1 11 // AddY 16 // CopyToY 20 // Jump 15 15 1 // Print newline 10 9 2 50 // End 65 // Data A-Z 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0 1 // Data 1-10 2 3 4 5 6 7 8 9 10 0

.1000 30

sample2.txt

23 // line one 15 23 // line two 30 23 // line three 51 23 // line four 86 23 // line five 103 23 // line six 142 23 // line seven 163 50

// line one 1 ld 4 4 27 push 23 call spaces 206 28 remove parm 1 ld 6 6 27 push 23 call line 178 28 remove parm 23 call newline 220 24 return

// line two 1 32 9 2 1 ld / 47 9 2 1 ld 9 9 27 push 23 call spaces 206 28 remove parm 1 load \ 92 9 2 23 call newline 220 24 return

// line three 1 ld / 47 9 output 2 1 three spaces 32 9 2 9 2 9 2 23 print eye 225 1 two spaces 32 9 2 9 2 23 print eye 225 1 two spaces 32 9 2 9 2 1 load \ 92 9 2 23 call newline 220 24 return

// line four 1 load | 124 9 put 2 1 ld 11 11 27 push 23 call spaces 206 28 remove parm 1 load | 124 9 put 2 23 call newline 220 24

// line five 1 load \ 92 9 2 1 three spaces 32 9 2 9 2 9 2 1 load \ 92 9 2 1 ld 4 4 27 push 23 call underscore 192 28 remove parm 1 load / 47 9 2 1 two spaces 32 9 2 9 2 1 load / 47 9 2 23 call newline 220 24 return

// line six 1 32 9 2 1 ld \ 92 9 2 1 ld 9 9 27 push 23 call spaces 206 28 remove parm 1 load / 47 9 2 23 call newline 220 24 return

// line seven 1 ld 4 4 27 push 23 call spaces 206 28 remove parm 1 ld 6 6 27 push 23 call line 178 28 remove parm 23 call newline 220 24 return

// print dash 1 ld 1 1 14 CopyToX 6 LoadSpX - get parm 14 CopyToX 1 ld - 45 9 output 2 26 decX 15 CopyFromX 22 JNE 183 183 24

// print underscore 1 ld 1 1 14 CopyToX 6 LoadSpX - get parm 14 CopyToX 1 ld _ 95 9 output 2 26 decX 15 CopyFromX 22 JNE 197 197 24

// print space 1 ld 1 1 14 CopyToX 6 LoadSpX - get parm 14 CopyToX 1 ld ' ' 32 9 output 2 26 decX 15 CopyFromX 22 JNE 211 211 24

// print newline 1 10 9 2 24

// print -* 1 ld dash 45 9 output 2 1 ld asterisk 42 9 output 2 24 return

.1000 30 interrupt handler - just return

sample3.txt

.0 1 // Load 10 10 14 // CopyToX 1 // Load A 65 9 // Output A 2 1 // Load newline 10 9 // Output newline 2 29 // Syscall 26 // DecX 15 // CopyFromX 22 // Jump NE Load A 3 50

.1000 27 // Push 15 // CopyFromX 27 // Push 17 // CopyFromY 27 // Push

2 // load data 1700 14 // CopyToX 25 // IncX 15 // CopyFromX 7 // Store data 1700

28 // Pop 16 // CopyToY 28 // Pop 14 // CopyToX 28 // Pop 30 // IRet

.1500 27 // Push 15 // CopyFromX 27 // Push 17 // CopyFromY 27 // Push

2 // load data 1700 9 // write value 1 1 // load newline 10 9 // write newline 2

28 // Pop 16 // CopyToY 28 // Pop 14 // CopyToX 28 // Pop 30 // IRet

.1700 0 // data

sample4.txt

19 // CopyFromSp 9 // Output 1 1 10 9 2 27 // push 19 // CopyFromSp 9 // Output 1 1 10 9 2 28 // pop 19 // CopyFromSp 9 // Output 1 1 10 9 2 29 // interrupt 2 // try to load from protected memory, should fail with error 1000 50 .1000 30 .1500 19 // CopyFromSp 9 // Output 1 1 10 9 2 27 // push 19 // CopyFromSp 9 // Output 1 1 10 9 2 28 // pop 19 // CopyFromSp 9 // Output 1 1 10 9 2 30

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions