Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

converting c++ code to Marie instructions (.mas), Thanks, I'll sure to leave GREAT feed backs. Program in C++ // Example program #include #include using namespace

converting c++ code to Marie instructions (.mas), Thanks, I'll sure to leave GREAT feed backs.

Program in C++

// Example program

#include

#include

using namespace std;

int main()

{

char address[3];

int tag;

int cache[4][2]={{1,5}, {2,4}, {3,2}, {6,0}};

int setNumberFirstBit, setNumberSecondBit, setNumber;

cout << "Enter the address as hex(in small letters): "<

cin >> address;

//get the tag which is the first 3 bits.

//You can also use direct conversion to binary and shift operators to do this

//int(address[0])>>1. But conversion to int or hex is not direct in c/c++

switch(address[0]){

case '0':

tag = 0;

setNumberFirstBit = 0;

break;

case '1':

tag = 0;

setNumberFirstBit = 1;

break;

case '2':

tag = 1;

setNumberFirstBit = 0;

break;

case '3':

tag = 1;

setNumberFirstBit = 1;

break;

case '4':

tag = 2;

setNumberFirstBit = 0;

break;

case '5':

tag = 2;

setNumberFirstBit = 1;

break;

case '6':

tag = 3;

setNumberFirstBit = 0;

break;

case '7':

tag = 3;

setNumberFirstBit = 1;

break;

case '8':

tag = 4;

setNumberFirstBit = 0;

break;

case '9':

tag = 4;

setNumberFirstBit = 1;

break;

case 'a':

tag = 5;

setNumberFirstBit = 0;

break;

case 'b':

tag = 5;

setNumberFirstBit = 1;

break;

case 'c':

tag = 6;

setNumberFirstBit = 0;

break;

case 'd':

tag = 6;

setNumberFirstBit = 1;

break;

case 'e':

tag = 7;

setNumberFirstBit = 0;

break;

case 'f':

tag = 7;

setNumberFirstBit = 1;

break;

default: printf("Invalid Hex code");

return 0;

}

//We only need the first bit of the second hex. Other three bits are offset

if(address[1]>='0' && address[1]<'8'){

setNumberSecondBit = 0;

}

else if(address[1]=='8'|| address[1]=='9'||(address[1]>='a' && address[1]<='f')){

setNumberSecondBit = 1;

}

else{

printf("Invalid Hex code");

return 0;

}

//convert setNumber from binary bits to decimal

setNumber = setNumberFirstBit * 2 + setNumberSecondBit;

if(cache[setNumber][0]==tag || cache[setNumber][1]==tag){

//cache hit

cout<<"1";

}

else{

//cache miss

cout<< "0";

}

return 0;

}

It should look like this

C++ to marie:

ORG 0

LOAD I

LOAD X

COMPARE X==I

STORE A

LOAD Z

OUTPUT

SQUARE A

I, DEC 1

X, DEC 1%100

A, DEC 1

This can by accomplish by using Clear and AddI.

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_2

Step: 3

blur-text-image_3

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

Students also viewed these Databases questions

Question

What are the two major types of materials, and how do they differ?

Answered: 1 week ago