Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
I have a coding assignment that requires me to create a program in C#, within Visual Studio, that simulates MARIE. It needs to have global variables such as PC, MAR, MBR, AC, IR, etc. It needs to implement, fetch, decode and execute cycles. For instance, during the fetch cycle, the code needs to first place PC in MAR, then use MAR to access memory (array element) and grab the content and put it in IR and increment PC.

For example, let's say PC = 0, the code will place PC which is zero inside MAR, now MAR is zero, then the program will read memory[MAR] and save its content in IR register (variable) and increment PC which becomes 1. Next, you will check the first 4 bits of IR (in this example it is 0001, based on the 4 bits, the program needs to call Load function. Since Load command has an operant, the code also needs to put the remaining 12 bits of the IR inside MAR to be able to access the memory location MAR. Next, it grabs the content of memory[MAR] and converts it into integer (decimal value) and loads it into AC.

Some of these variables must be of type string, for instance the IR register and some of them such as PC is of type int. It also needs to implement functions to convert binary to decimal and a function to convert decimal to binary.

Here are some of the arrays that need to go into visual studio but I don't know what else needs to go with it:

C#
memory[0] = "0001000000010001"; // Load Addr

memory[1] = "0010000000010010"; // Store Next

memory[2] = "0001000000010011"; // Load Num

memory[3] = "0100000000010110"; //Subt One

memory[4] = "0010000000010101"; // Store Ctr

memory[5] = "0001000000010100"; //LOOP: Load Sum

memory[6] = "1011000000010010"; // AddI Next

memory[7] = "0010000000010100"; //Store Sum

memory[8] = "0001000000010010"; //Load Next

memory[9] = "0011000000010110"; //Add One

memory[10] = "0010000000010010"; //Store Next

memory[11] = "0001000000010101"; // Load Ctr

memory[12] = "0100000000010110"; //Subt One

memory[13] = "0010000000010101"; //Store Ctr

memory[14] = "1000000000000000"; // Skipcond

memory[15] = "1001000000000101"; //Jump

memory[16] = "0111000000000000"; // Halt

memory[17] = "0000000000010111"; //Addr

memory[18] = "0000000000000000"; // Next

memory[19] = "0000000000000101"; // Num

memory[20] = "0000000000000000"; //Sum

memory[21] = "0000000000000000"; // Ctr

memory[22] = "0000000000000001"; //One

memory[23] = "0000000000001010"; //Dec 10

memory[24] = "0000000000001111"; // Dec 15

memory[25] = "0000000000010100"; //Dec 20

memory[26] = "0000000000011001"; //Dec 25

memory[27] = "0000000000011110"; //Dec 30


What I have tried:

I've tried seeing if YouTube has any tutorials and so I don't know where to start and I've never coded anything like this before.
Posted
Updated 12-Nov-21 11:31am
v3
Comments
PIEBALDconsult 12-Nov-21 15:54pm    
That reminds me of an assignment from my "History of Programming Languages" (or whatever) course back in college. But it looks like you have more bytes to work with, we had ten.
It's really pretty simple.
BillWoodruff 12-Nov-21 19:16pm    
If we/others do your homework, you will learn nothing.

How do you code a program that simulates MARIE? - Reddithttps://www.reddit.com › AskProgramming › comments
2 days ago — Find the specs for how a MARIE CPU is supposed to work, implement a ... Going deeper, maybe you want to simulate each clock cycle, ...

How do I code a program in C# within Visual Studio that ...https://stackoverflow.com › questions › how-do-i-code-...
4 hours ago — I have a coding assignment due in 3 days that requires me to create a program in C#, within Visual Studio, that simulates MARIE.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
Start by reading the processor description you have been given - this may help: The MARIE architecture[^] and think about what you have to do.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
Jeff Doyle Nov2021 12-Nov-21 21:07pm    
Can you delete my question? I figured it out: https://www.codeproject.com/Questions/5317498/How-do-I-code-a-Csharp-program-within-visual-studi
OriginalGriff 13-Nov-21 1:59am    
That's not something we do: it means others with a similar problem can't learn from the posted answers.
All you're doing is tracking the values of a hypothetical CPU, "registers". They're values, nothing more.

Your input is going to be a list of "instruction" values in "memory", which you have to pull apart and evaluate, and are going to tell you how to manipulate the values in your "registers."

The "memory" you're using is just an array of values. So, when your CPU starts, it gets the first "memory" location, array index 0, and you start deconstructing that value into the various parts you need as spelled out in the assignment.

That's it.

There's no such thing as global variables in any .NET language as the .NET CLR does not support it. So, you have to start with a class to hold the values. Your application is going to start with a class, as with any other app.
C#
public class MarieCPU
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900