Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

you are to take the following y86 and fill out the program with the proper instructions to match it. The immediate values are in little

you are to take the following y86 and fill out the program with the proper instructions to match it. The immediate values are in little endian.

printall Single byte instruction 0xC0 prints out the values stored in all 15 registers

printreg reg Two byte instruction 0xD0, 0xrA:F print out the value of the register indicated by rA

printmem disp(reg) 10 byte instruction 0xE0, 0xrA:F, 8 byte displacement print out the 8 byte constant stored at address contents(rA) + displacement

0x0

30F6FECA000000000000D06FE0EF5000000000000000502E5000000000000000D02F501E5800000000000000D01F6011D01F628861616062D01F402E5000000000000000C0E0EF500000000000000000AA88000000000000341200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

(THE ABOVE INFORMATION MUST BE CONVERTED TO Y86 INSTRUCTION THEN IMPLEMENT INTO C)

#include

#include

int Pop(int), Push(int), Call(int), Ret(int), Jump(int);

int IRmov(int), RRmov(int), RMmov(int), MRmov(int);

int OPx(int);

int printall(int), printreg(int),printmem(int);

char SF = 0x00;

char ZF = 0x00;

extern char memory[] ;

extern int PC ;

long int regs[16];

char *regname[15] = {"%rax","%rcx","%rdx","%rbx","%rsp","%rbp",

"%rsi","%rdi","%r8","%r9","%r10","%r11","%r12","%r13","%r14"};

void

execute(int PC) {

int done = 0;

char byte;

char opcode ;

while (!done) {

byte = memory[PC];

opcode = (byte >> 4)&0xf;

switch (opcode) {

case 0: printf("Halting at instruction 0x%x ",PC);

done = 1; break; //halt

case 1: PC++; break; // nop

case 2: PC = RRmov(PC);

break;

case 3: PC = IRmov(PC);

break;

case 4: PC = RMmov(PC);

break;

case 5: PC = MRmov(PC);

break;

case 6: PC = OPx(PC);

break;

case 7: PC = Jump(PC);

break;

case 8: PC = Call(PC);

break;

case 9: PC = Ret(PC);

break;

case 10: PC = Push(PC);

break;

case 11: PC = Pop(PC);

break;

case 12: PC = printall(PC);

break;

case 13: PC = printreg(PC);

break;

case 14: PC = printmem(PC);

break;

default:

printf("# unknown op at PC=0x%x ",PC); PC++;

}

}

}

int

printreg(int PC) {

return PC+1;

}

int

printall (int PC) {

return PC+1;

}

int

printmem(int PC) {

return PC + 1;

}

int

IRmov(int PC) {

return PC+1;

}

int

RRmov(int PC) {

return PC+1;

}

int

RMmov(int PC) {

return PC+1;

}

int

MRmov(int PC) {

return PC+1;

}

int

Jump(int PC ) {

return PC+1;

}

int

Call(int PC) {

return PC + 1;

}

int

Ret(int PC) {

return PC+1;

}

int

Push(int PC) {

return PC+1;

}

int

Pop(int PC) {

return PC+1;

}

int

OPx(int PC) {

return PC+1;

}

This must be written in C

please take your time, I need help especially with rmov and mrmov.

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions