diff --git a/instructions.c b/instructions.c index c84f16d..9404525 100644 --- a/instructions.c +++ b/instructions.c @@ -16,8 +16,12 @@ // Return: instruction_type: R_TYPE or I_TYPE (see structures) // instruction_type get_type_of_instruction(uint32_t instruct) { - // TODO - return NULL; + if (bit_select(instruct, 26, 32) == 0) { + return R_TYPE; + } else { + return I_TYPE; + } + } // end get_type_of_instruction() function // ------------------------------------ diff --git a/lab04 b/lab04 new file mode 100755 index 0000000..8f81b49 Binary files /dev/null and b/lab04 differ diff --git a/lab04.c b/lab04.c index f71f0d7..6054347 100644 --- a/lab04.c +++ b/lab04.c @@ -32,10 +32,12 @@ int main() { return EXIT_SUCCESS; if (get_type_of_instruction(instruct) == R_TYPE) { + printf("R_TYPE instruction\n"); r_instruction* r_instruct = create_r_instruction(instruct); execute_r_instruction(r_instruct); free(r_instruct); } else { // I_TYPE + printf("I_TYPE instruction\n"); i_instruction* i_instruct = create_i_instruction(instruct); execute_i_instruction(i_instruct); free(i_instruct); @@ -58,11 +60,11 @@ int main() { // ------------------------------------ // Takes the r_instruction -// you created in Part 1 and, based on the MIPS instruction, -// performs the operation and updates the 'registers' array +// you created in Part 1 and, based on the MIPS instruction, +// performs the operation and updates the 'registers' array // (see top of file). // -// Hint: the "func" bits determine the operation (i.e., SLL, +// Hint: the "func" bits determine the operation (i.e., SLL, // SRA, ADD, SUB, AND, OR). // // Arguments: r_instruction structure @@ -75,11 +77,11 @@ void execute_r_instruction(r_instruction* instruct) { // ------------------------------------ // Takes the i_instruction -// you created in Part 1 and, based on the MIPS instruction, -// performs the operation and updates the 'registers' array +// you created in Part 1 and, based on the MIPS instruction, +// performs the operation and updates the 'registers' array // (see top of file). // -// Hint: the "opcode" bits determine the operation (.e., ADDI, +// Hint: the "opcode" bits determine the operation (.e., ADDI, // ANDI, ORI). // // Arguments: i_instruction structure