Question: Create a program that simulates a variant of the Tiny Harvard Architecture. In this implementation, memory ( RAM ) is split into Instruction Memory (
Create a program that simulates a variant of the Tiny Harvard Architecture. In this implementation, memory RAM is split into Instruction Memory IM and Data Memory DM Your code must implement the basic instruction set architecture ISA of the Tiny Machine Architecture:
LOAD
ADD
STORE
SUB
IN
OUT
END
JMP
SKIPZ
Each piece of the architecture must be accurately represented in your code Instruction Register, Program Counter, Instruction Memory IM MAR MDR MAR and MDR are connected to the IM Data Memory, MAR MDR MAR and MDR are connected to the DM and Accumulator. Instruction Memory will be represented by an integer array, and each instruction will use elements of the array one for OP and the other one for the address Data Memory will be represented by an integer array, and each data value uses an element of the DM array. Your Program Counter will begin pointing to the first instruction of the program PC The virtual machine VM you are implementing should provide output according to the input file. Along with this output, your program should provide status messages identifying details on the workings of your simulator. Output text does not have to reflect my example wordforword, but please provide detail on the program as it runs in a readable format that does not conflict with the actual output of your VM After each instruction print the current state of the Program Counter, Accumulator, and Data Memory. The INPUT instruction is the only one that should prompt an interaction from the user.
Example:
Reading Program...
Program Loaded.
Run.
PC A NULL DM input value
X
PC A X DM outputting accumulator to screen
X
PC A X DM storing accumulator to memory location
PC A X DM X
etc
Program complete.
The code text must be loaded starting at location and therefore the PC must be initialized to zero PC Any program that is loaded somewhere else for example loaded at memory location will get a zero. The PC should start from and Data is in Data Memory which is another array. You must run a program to multiply numbers. We will test your HW running a program to multiply numbers; numbers will not be validated. you can use two integers as inputs and
This is my code. Check to ensure that it meets the requiremtns and works.
#include
Constants for instruction set architecture
#define LOAD
#define ADD
#define STORE
#define SUB
#define IN
#define OUT
#define END
#define JMP
#define SKIPZ
Memory sizes
#define IMSIZE
#define DMSIZE
Function prototypes
void loadprogramconst char filename;
void fetchexecutecycle;
void printstate;
Registers
int PC ; Program counter
int MAR MDR; Instruction Memory Registers
int MAR MDR; Data Memory Registers
int IR; Instruction Register
int A ; Accumulator
Memory arrays
int IMIMSIZE; Instruction Memory
int DMDMSIZE; Data Memory
int mainint argc, char argv
if argc
printfUsage: s
argv;
return ;
Load program from file
loadprogramargv;
Run fetchexecute cycle
printfProgram Loaded. Run.
;
fetchexecutecycle;
printfProgram complete.
;
return ;
void loadprogramconst char filename
FILE file fopenfilenamer;
if file
printfError: Unable to open file s
filename;
return;
int opcode, address;
int i ;
while fscanffiled d &opcode, &address EOF && i IMSIZE
IMi opcode;
IMi address;
i;
fclosefile;
void fetchexecutecycle
int run ;
while run
Fetch
MAR PC;
PC ;
MDR IMMAR;
IR MDR;
Execute
switch IR
case LOAD:
LOAD
MAR IMMAR;
MDR DMMAR;
A MDR;
break;
case ADD:
ADD
MAR IMMAR;
MDR DMMAR;
A MDR;
break;
case STORE:
STORE
MAR IMMAR;
DMMAR A;
break;
case SUB:
SUB
MAR IMMAR;
MDR DMMAR;
A MDR;
break;
case IN:
IN
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
