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

Task: (O) Write a program in C, or C++ to simulate the execution of the followin

ID: 3598162 • Letter: T

Question

Task: (O) Write a program in C, or C++ to simulate the execution of the following 5 instruction program: LDM(x) Loading form memory location# xin to the AC AD M(y) Adding the value in the AC to the content of u+1 memory location # y Store the AC content in the memory location #z Divide the content of the AC by content of memory #w Store the content of the AC in memory address #b the result is in the AC u+2 u+3 u+4 ST M(z) DV M(a) ST M(b) Your program will print out the content of registers as the execution of the above code progresses. Each instruction execution will result in changes in the CPU registers, as you know. For example before the "fetch" of the first instruction the content of PC is set to u. Allow the user to enter this value. Your program will print out the details of each of the following register each time the content of a register is changed: The MAR, the MBR, PC register, the AC register and the IR in this specific order.

Explanation / Answer

#include<iostream>

using namespace std;

int main(){

int i,j,AC,u=4000,y=6001,a=7050,x=4500,z=6500,b=7600;

int array[5][2]={{4500,50},{6001,45},{6500,89},{7050,77},{7600,90}};

cout<<"Content of the memory location before ";

for(i=0;i<5;i++){

cout<<array[i][0]<<" "<<array[i][1]<<endl;

}

for(i=0;i<5;i++){

if(array[i][0] == x){

cout<<"if x = "<<x<<" ";

AC = array[i][1];

cout<<u++<<" AC = "<<AC<<endl;

}

if(array[i][0] == y){

cout<<"if y = "<<y<<" ";

AC += array[i][1];

cout<<u++<<" AC = "<<AC<<endl;

}

if(array[i][0] == z){

cout<<"if z = "<<z<<" ";

array[i][1] = AC;

cout<<u++<<" AC = "<<AC<<endl;

}

if(array[i][0] == a){

cout<<"if a = "<<a<<" ";

AC /= array[i][1];

cout<<u++<<" AC = "<<AC<<endl;

}

if(array[i][0] == b){

cout<<"if b = "<<b<<" ";

array[i][1] = AC;

cout<<u++<<" AC = "<<AC<<endl;

}

}

cout<<"Content of the memory location after ";

for(i=0;i<5;i++){

cout<<array[i][0]<<" "<<array[i][1]<<endl;

}

return 0;

}

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