Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a simulator using CPP language. 3.3 Simulator 3.3.1 Overview This is the major part of your project 1. You need to have a full

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Write a simulator using CPP language.

3.3 Simulator 3.3.1 Overview This is the major part of your project 1. You need to have a full understanding of how computer executes programs, and how are things stored in memory. Your code will need to be capable of executing the MIPS code line by line. 3.3.2 Memory & register simulation The first thing you will need to do is memory simulation. Think about your simulator as a mini- computer, that has its own main memory, CPU, etc. To simulate main memory, you need to dynamically allocate a block of memory with C/C++, with a size of 6MB. Here is a figure of what does a real computer memory look like. 7fffffff hex Stack segment Dynamic data Static data Data segment 10000000 hex Text segment 400000 hex Reserved Your simulated memory should also have these components. Also, since most of you are using a 64-bit computer, you need to translate the real address of your allocated memory to a 32-bit simulated address. Specifically: 1. Let's say you have the pointer named "real_mem" storing the real address of the block of memory allocated. The first thing you need to do is to map the value of "real_mem" to 400000_hex. Then the real address will have a 1-to-1 mapping relationship to the simulated address. For instance, if the address mentioned in the MIPS testing file is 500000_hex (such as lw, where we want to load the data storing on 500000_hex), then, you should access it at real address of: (real_mem + 500000_hex - 400000_hex). 2. The dynamically allocated 6MB memory block is pointing at the start of your text segment, and your text segment will be 1MB in size. The end of text segment will be at simulated address 400000_hex+1MB, or at address real_mem+1MB. 3. The static data segment will start at simulated address 500000_hex, or at real address (real_mem+1MB). 4. The dynamic data segment will start at wherever your static data section ends. 5. The stack segment will start at the highest address A00000_hex (real_mem+6MB), and it grows downwards (whenever you put things in there, the address decreases). .data Strl: .asciiz "hello" intl: .word 1 in memory: | hell \-- I ! Here, each character of asciiz type occupies 1 byte, so "hell" occupies the first block. The first two bytes of the second block is used by "o" and a terminating sign"0", but the last two bytes of the second block is not used. However, when we put the next piece of data in the memory, we start a new block. The data type.word occupies 4 bytes, so the third block is assigned to this piece of data. 2. Assemble the text segment of the MIPS file (Section 3.2), and put the assembled machine code in the text segment of your simulated memory (the first line of code has the lowest address). The assembled machine code is 32 bits, which is 4 bytes. Thus, you can translate it to a decimal number and store it as an integer. 3.3.4 Start simulating Your code should maintain a PC, which points to the first line of code in the simulated memory. Your code should have a major loop, simulating the machine cycle. Following the machine cycle, your code should be able to: 1. Go to your simulated memory to fetch a line of machine code stored at the address PC indicates. 2. PC=PC+4 3. From the machine code, be able to know what the instruction is and do the corresponding things. The third step of the machine cycle requires you to write a C/C++function for each instruction to do what it's supposed to. For example, for the add instruction, we can write in C: void add (int* rs, ine* rt, int* rd) { *rd*rs art: } In the third step of the machine cycle, when we read a line of machine code and the corresponding instruction is add, we can simply call the function

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

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions

Question

2. Why has the conflict escalated?

Answered: 1 week ago

Question

1. How will you, as city manager, handle these requests?

Answered: 1 week ago