Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple simulation of a microprocessor system (HELP!)

Posted on 2003-11-25
5
Medium Priority
?
312 Views
Last Modified: 2010-04-01
How much sense does this make to anyone, i have been learning c++ for 8 weeks now and i been given two weeks to complete the fist part of my assignment which is below. The teacher is of no use and cant seem to explain anything, where would a good place to start be, i have been trying to use seperate header files for the different parts. Just seem to be getting more and more confused by it all, i certainly dont want the complete answer but some code to start me off would be great, so i can build on it.

Develop a series of classes that can be used together to provide a simple simulation of a microprocessor system comprising as a minimum a CPU, with its internal registers, and operations to fetch and execute instructions and Flash ROM which holds the program instructions.
 
The CPU should have four internal registers and the following instruction types:

Instruction                   Description
MOVE Rx,Ry                  move contents of Rx to Ry
MOVE data_value, Rx      move data value into  Rx
ADD Rx, Ry                  add Rx to Ry and store it in Ry
SUB Rx, Ry                                  subtract Rx from Ry and store it in Ry
OUTPUT Rx                                                output contents of Rx to display
HALT                        End of instructions
 where Rx and Ry represent  the registers R0 - R3

All instructions are encoded as a three single digit numbers d1d2d3 :-
The first digit is the op-code, the next two digits are operands for the instruction. If the instruction only requires a single register then it is the last digit. If any operands are not required then the digit value is zero.

The op-codes for the different instruction types are:-

Op-code       Instruction type
1            MOVE register to register
2            MOVE data to a register
3            ADD
4            SUB
5            OUTPUT
6            HALT

Examples of possible instruction codes and the equivalent instruction

Instruction code            Instruction
112                         MOVE R1, R2            
251                         MOVE 5, R1
301                         ADD R0, R1
430                        SUB R3, R0
502                         OUT R2
600                        HALT

1.      The FlashROM class should have the following functions/methods.

•      void program(int  p[]) - function receives an array (or could be done using a  pointer to an array) of values terminating
                with the HALT instruction. The purpose of this function is to read in the complete program and store it in the FlashROM
•       void erase() - erase all Flash ROM contents.
•      int read(int location) - return contents of the given location.

Write a short main function to test this class.

0
Comment
Question by:a_migdal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
bcladd earned 2000 total points
ID: 9818473
How much do you know about classes? Can you write a class? The reason I ask is this calls out for several classes:


class CPU - This will contain the registers
class FlashROM - contains the memory locations
class Computer - contains a CPU and a FlashROM

The CPU should have the four registers (sounds like an array to me) as well as an instruction pointer and an instruction register (adding a couple of bookkeeping registers to the 4; I would not put the ip or instruction register in the array). Then execution of a program is "simple":

while (1) { // forever
   ir = Flash.read(ip++);
   // decode ir
   // execute ir
}

That is an infinite loop but executing HALT will break out of it.

So, where to get started:

Since you have been given the interface for the FlashROM I would design that class. Where will you store the contents of the ROM? What data members will the FlashROM need? You'll of course need to be able to create and destroy FlashROMs. I would suggest writing a routine that will print the contents of the FlashROM on the screen. That way you can test the FlashROM without writing a CPU at all. Just have a main that looks something like this:

int main() {
    FlashROM testMemory;
    int testProgram = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 600 };

    testMemory.program(testProgram);
    testMemory.print();
}

should show the contents of the FlashROM are what you would expect. Notice that those may not be legal opcodes. No problem because FlashROM should not care about opcodes.

Hope this gives you somewhere to start. If you have questions (or you are not expected to use classes), then ask away.

-bcl
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9824313
I have been thinking about this (I wrote a very similar simulator back in my undergraduate days and have assigned this sort of thing before). I think writing a FlashROM class based on some simple container is your best way to start. Each memory location has to contain an int so you should have a container that holds ints at the heart of the class.  

If you need any C++ concepts explained (you complained about the instructor; my condolences), ask about them.

-bcl
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9865039
a_migdal,
I guess you have missed your deadline.  Would you like to close this question or do you need some more help?
-- DanRollins, EE Page Editor
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10285831
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bcladd {http:#9818473}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question