Provide a step-by-step description of the sequence of operationsthat must take p
ID: 667485 • Letter: P
Question
Provide a step-by-step description of the sequence of operationsthat must take place within a MIPS processor to fetch and executethe following instructions
() or Rd, Rs, Rt
Explanation / Answer
instruction.txt R add rd rs rt 0 rs rt rd 0 32 R addu rd rs rt 0 rs rt rd 0 33 R sub rd rs rt 0 rs rt rd 0 34 R subu rd rs rt 0 rs rt rd 0 35 R and rd rs rt 0 rs rt rd 0 36 R or rd rs rt 0 rs rt rd 0 37 R xor rd rs rt 0 rs rt rd 0 38 R nor rd rs rt 0 rs rt rd 0 39 R slt rd rs rt 0 rs rt rd 0 42 R sltu rd rs rt 0 rs rt rd 0 43 R sll rd rs rt 0 rs rt rd shamt 0 R srl rd rs rt 0 rs rt rd shamt 2 R sra rd rs rt 0 rs rt rd shamt 3 R sllv rd rs rt 0 rs rt rd 0 4 R srlv rd rs rt 0 rs rt rd 0 6 R srav rd rs rt 0 rs rt rd 0 7 R jr rd rs rt 0 rs rt rd 0 8 I addi rt rs immediate 8 rs rt immediate I addiu rt rs immediate 9 rs rt immediate I andi rt rs immediate 12 rs rt immediate I ori rt rs immediate 13 rs rt immediate I xori rt rs immediate 14 rs rt immediate I lui rt rs immediate 15 rs rt immediate I beq rs rt label 4 rs rt immediate I bne rs rt label 5 rs rt immediate I lw rt immediate rs 35 rs rt immediate I sw rt immediate rs 43 rs rt immediate I slti rt immediate rs 10 rs rt immediate I sltiu rt immediate rs 11 rs rt immediate J j label 2 target J jal label 3 target instructions.h #ifndef INSTRUCTION_H_ #define INSTRUCTION_H_ #include #include "..dasm_lenDef.h" #define NONE -1 #define MAX_CODE_FIELD_LEN 27 //max field length in code(target->26) #define MAX_CODE_FIELD_NUM 6//max field number in the code(op rs rt rd shamt func) #define MAX_INSTR_NUM 200//max instruction lines in the text #define MAX_INSTR_STR_LEN 80 //max length of string of instruction (a line) #define MAX_INSTR_FIELD_STR_LEN 20//max length of string in a field of instruction #define MAX_INSTR_FIELD_NUM 6//max argument number in the instruction extern struct instruction_table{ char instruction[MAX_INSTR_FIELD_NUM][MAX_INSTR_FIELD_STR_LEN];//type, operation and other fields //add type field for easy to print char code[MAX_CODE_FIELD_NUM][MAX_CODE_FIELD_LEN];//the value in decimal or define the format }; extern struct instruction_table instrTable[MAX_INSTR_NUM]; extern size_t instrNum; #define OP_CODE_NUM 128 #define FUNCT_CODE_NUM 127 extern int *opStrHashFindTbl;//table[hash("add")]->instructTable[i][] extern int opCodeFindTbl[OP_CODE_NUM]; //table[opcode]->instructTable[i][] extern int functCodeFindTbl[FUNCT_CODE_NUM]; //table[funct]->instructTable[i][] extern int *opStrHashFindTbl; extern void ReadInstr(void); extern void InitInstrTable(void); extern void DestroyInstrTable(void); #endif /* INSTRUCTION_H_ */ instructions.c #include #include #include #include "dasm_instruction.h" #include "..dasm_GetStr.h" #include "..dasm_header.h" //#define INSTR_BUG struct instruction_table instrTable[MAX_INSTR_NUM]; size_t instrNum = 0;//number of available instructions in the table int opCodeFindTbl[OP_CODE_NUM]; //table[opcode]->instructTable[i][] int functCodeFindTbl[FUNCT_CODE_NUM]; //table[funct]->instructTable[i][] void ReadInstr(void){ //read in instructions to global table void InitInstrTable(void); memset(instrTable, 0, sizeof(struct instruction_table) * MAX_INSTR_NUM); FILE* pFile; if((pFile = fopen("instruction.txt", "r")) == NULL) ERROR("Cannot open the instruction.txt file "); size_t i = 0, j = 0, count = 0; char str[MAX_INSTR_STR_LEN]; char *line; while(fgets(str, MAX_INSTR_STR_LEN, pFile) != NULL){//get in string //for every line line = str; char *oldLinePtr = line; j = 0; if(count % 2 == 0){//instruction while((line = GetStr(instrTable[i].instruction[j], line)) != oldLinePtr){ //extract a string j++; oldLinePtr = line; } } else{//code while((line = GetStr(instrTable[i].code[j], line)) != oldLinePtr){//get a string j++; oldLinePtr = line; } } count++; i = count / 2; } instrNum = i; InitInstrTable(); fclose(pFile); } void InitInstrTable(void){ memset(opCodeFindTbl, NONE, sizeof(size_t) * OP_CODE_NUM); memset(functCodeFindTbl, NONE, sizeof(size_t) * FUNCT_CODE_NUM); //create table reg_type op = 0; reg_type funct = 0; size_t i = 0; for(i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.