Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this lab you will simulate a context stack using C++ programming language. Fi

ID: 3887682 • Letter: I

Question

In this lab you will simulate a context stack using C++ programming language. First, assume that the following information is sufficient to express the state of the system:

·        PC: a 32-bit program counter

·        registers 0 – 3: 4 registers, each containing 32 bits

·        system flags: 32 Boolean flags that express the state of the machine. (For example, one flag might mean that the system is running in user mode, i.e., that it has no special privileges; and another may indicate that a divide-by-zero has taken place.) For purposes of this assignment, the meaning of the system flags is not important; you will simply record them.

Create a class Context that can store this information. Can C++ int be used? You probably don’t want to deal directly with 32 individual bits. Create a stack of Context. Test your system by writing a driver that uses the following algorithm:

1.      Set the state of the system randomly.

2.      Allow the user to enter either ‘I’ for Interrupt, or ‘R’ for Return from interrupt. Each time an interrupt is generated, the old context is pushed onto the stack, and a new context is created randomly. When a return is generated, the current context is thrown away, the top of the stack is popped and the state of the system is set from the context on top of the stack. (An attempt to return when nothing is on the stack is an error.)

3.      Each time the state of the system changes, print out the current state so you can check that your system works. Output the data in hexadecimal, by using the hex output modifier:

             cout << hex << pc;

Explanation / Answer

D can link directly with C and C++ (*) static and shared libraries without any wrappers or additional overhead (compared to C and C++). Supported subset of C++ platform specific ABI (e.g. GCC and MSVC):

Generally D uses the platform linker on each platform (ld.bfd, ld.gold, etc. on Linux), the exception being Windows, where Optlink is used by default. MSVC link.exe is also supported, but the Windows SDK must be first downloaded.

D features missing from C and C++

Some the new features that a C/C++ programmer will find are:

First class:

You can find a runnable example at dpaste.dzfl.pl - online compiler and collaboration tool dedicated to D.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote