California State University San Marcos Accumulator Virtual Machine Questions

Question Description

[yono001@empress ~]$ g++ –version

g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)

/* this is the version of the c++ compiler so it must be compatible*/

Also, follow the programming standards page.

Write an interpreter C++ for a very simple pseudo-code. The instructions on a one-accumulator virtual machine are as follows:

Format Meaning

1XXX Load accumulator with contents of XXX

2XXX Store accumulator into location XXX

3XXX Add contents of XXX to accumulator

4XXX Subtract contents of XXX from accumulator

5XXX Multiply contents of XXX to accumulator

6XXX Divide contents of XXX by accumulator

7XXX Branch to instruction XXX if accumulator is positive

8XXX Branch to instruction XXX if accumulator is negative

9XXX Stop (except 9999)

The format of a pseudo-code program is as follows:

Initial Data Values

9999

Pseudo code program consists of the above instructions

9999

The memory unit of our virtual machine is 2000 words and each word holds an integer less than or equal to +9999. The first half of the memory is used for storing data and the second half is for storing program instructions. The initial data values should be read into the beginning of the data area of the memory unit in that order. The validity of the values in the memory should always be checked. The pseudo code instructions should be read into the program instruction area of the memory unit before the program execution cycles start.

You will have to implement your program, say, interpreter.c, on our Unix system on empress.csusm.edu. You are supposed to prepare a pseudo code test program as the input to your pseudo-code interpreter. The output of your interpreter has to demonstrate that at least one instruction of each format in your test program is executed for at least once and both possibilities of the branch instruction are tested. A shell command script file compiling and running your program should also be prepared. The files of source program, input, output, and shell script must be submitted as one zipped file.

The documentation, implementation and testing of your program should be done according to the Standards of Programming Assignments.

A sample input file (PseudoCodeTestProgram) to your program is as follows:

1

2

3

4

5

9999

1000

2001

3004

4001

5002

6004

7004

8003

9000

9999

The content of a sample shell script file, say, interpreter.sh, consisting Unix commands is as follows:

gcc –o interpreter.out interpreter.c

interpreter.out < PseudoCodeTestProgram > OutputDisplay

Its sample output file (OutputDisplay) could have the following content:

ACC = 0 PC = 0 Next Instruction = 1000

Initialized Memory = 0:1, 1:2, 2:3, 3:4, 4:5

ACC = 1 PC = 1 Next Instruction = 2001

Initialized Memory = 0:1, 1:2, 2:3, 3:4, 4:5

ACC = 1 PC = 2 Next Instruction = 3004

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 6 PC = 3 Next Instruction = 4001

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 5 PC = 4 Next Instruction = 5002

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 15 PC = 5 Next Instruction = 6004

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 3 PC = 6 Next Instruction = 7004

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 3 PC = 4 Next Instruction = 5002

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 9 PC = 5 Next Instruction = 6004

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 1 PC = 6 Next Instruction = 7004

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 1 PC = 4 Next Instruction = 5002

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 3 PC = 5 Next Instruction = 6004

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 0 PC = 6 Next Instruction = 7004

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 0 PC = 7 Next Instruction = 8003

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

ACC = 0 PC = 8 Next Instruction = 9000

Initialized Memory = 0:1, 1:1, 2:3, 3:4, 4:5

Prof. Angela

4.6/5

Calculate Price


Price (USD)
$
Need Help? Reach us here via Whatsapp.