Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instruction Set Simulator (ISS) EE312 Introduction to Computer Architecture 1. Introduction In this Project, you will implement an instruction set simulator (ISS) for the KAIST

Instruction Set Simulator (ISS)

EE312 Introduction to Computer Architecture

1. Introduction In this Project, you will implement an instruction set simulator (ISS) for the KAIST RISC Processor 2.0 (KRP 2.0). The ISS should follow the instruction set architecture (ISA) specified in KRP Users Manual, and meet the requirements in Section 2. 2. Requirements Language: C/C++ Project environment: To be announced Execution file name: krpiss Output file: A dump file of the data memory Data memory size: 4KB Program memory size: 4KB Endian: Little endian 3. ISS Implementation Functions For every instruction, display the following information (1) Program Counter (PC) (2) Instruction Register (IR, the instruction being executed) (3) Interrupt Enable (IE) (4) Interrupted PC (IPC) (5) General-purpose registers (GPR) (6) Memory address and data being accessed (NOTE: Memory access instructions only) How to Execute

krpiss input_file_name output_file_name

1) When started, ISS is idle waiting for the users command 2) When s is typed on the prompt : Execute one instruction and display the prompt 3) When r is typed on the prompt : The entire program is executed to the end without displaying the temporary information. A. The final values of the PC, IR, IE, IPC, GPR should be displayed. B. The contents of the data memory at a specific address should be displayed and DUMPED into the output file.

Sample Code Given:

//Krpiss.h

#define IMEM_SIZE /*Define memory size here*/

#define DMEM_SIZE /*Define memory size here*/

unsigned int reg[32]; /*General purpose registers*/

unsigned int PC; /*Program counter*/

unsigned int IPC; /*Interrupted PC*/

unsigned int IE; /*Interrupt enable*/

unsigned int BP; /*Break point*/

unsigned char* pm; /*Program memory*/

unsigned char* dm; /*Data memory*/

FILE* fp_dump; /*Pointer for dumping dm*/

/*Functions*/

void view_reg(unsigned int inst);

int init_mem(char *file_name);

void process(unsigned int cmd, unsigned int inst);

//krpiss.c

#include

#include

#include

#include "krpiss.h"

int main(int argc, char** argv) {

unsigned int Inst = 0;

char str[100];

char in = NULL;

/*Special-purpose register initialization*/

PC = 0;

IE = 0;

IPC = 0;

/*Program memory initialization*/

init_mem(argv[1]);

/*Data memory initialization*/

fp_dump = fopen(argv[2], "w");

if(fp_dump == NULL) {

printf("Cannot open the file. ");

exit(1);

}

/*Program start*/

printf("======================================================================== ");

printf(" KRP 2.0 Instruction Set Simulator ");

printf("======================================================================== ");

printf("Request: ");

printf(">> ");

while(1) {

in = getchar();

Inst = (pm[PC+3]<<24) | (pm[PC+2]<<16) | (pm[PC+1]<<8) | pm[PC];

switch(in) {

case 's' : /*Process an instruction*/

process(0, Inst);

view_reg(Inst);

PC = PC+4;

break;

case 'r' : /*Recursively process*/

while(PC != (BP<<2)) {

Inst = (pm[PC+3]<<24) | (pm[PC+2]<<16) | (pm[PC+1]<<8) | pm[PC];

process(1, Inst);

PC = PC+4;

}

break;

case 'b' : /*Set break point*/

printf("break point: ");

scanf("%s", str);

BP = atoi(str);

break;

case 'd' : /*Display gpr*/

view_reg(Inst);

break;

case 'q' : /*Quit*/

exit(0);

break;

}

if (in != ' ')

printf(">> ");

}

fclose(fp_dump);

return 0;

}

void view_reg(unsigned int inst) {

int i, j, index;

printf("PC :%08X IR :%08X ", PC, inst);

printf("IE :%01X IPC:%08X ", IE, IPC);

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

for (j=0; j<4; j++) {

index = 4*i+j;

printf("reg[%2d]: %d\t", index, reg[index]);

}

printf(" ");

}

}

int init_mem(char *file_name) {

int inc;

unsigned char tmp_char;

int addr;

FILE *fp;

pm = (unsigned char*)malloc(IMEM_SIZE*sizeof(unsigned char));

dm = (unsigned char*)malloc(DMEM_SIZE*sizeof(unsigned char));

inc = 0;

fp = fopen(file_name, "rb");

if(fp == NULL) {

printf("Cannot open the file. ");

exit(1);

}

while(inc < IMEM_SIZE) {

fread(&tmp_char, sizeof(unsigned char), 1, fp);

if(feof(fp)) break;

pm[inc] = tmp_char;

inc++;

}

fclose(fp);

return 0;

}

void process(unsigned int cmd, unsigned int inst) {

/////////////////////////////////

// Write your ISS program here //

/////////////////////////////////

/*cmd 0: A process when a command 's' is entered*/

/*cmd 1: A process when a command 'r' is entered*/

}

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions