int main(int argc, const char * argv[]) { initialize(); testPrint(create_rtype_hex(FC_ADD, 0x0000, I_T0, I_T1, I_T2, OC_ADD)); testPrint(create_itype_hex(0x0001, I_T0, I_ZERO, OC_ADDI)); testPrint(create_jtype_hex(0xCD1234, OC_J)); testPrint(create_itype_hex(0xBBBB, I_T0, I_ZERO, OC_LUI)); testPrint(create_itype_hex(0xA03B, I_T0, I_T1, OC_LW)); testPrint(create_itype_hex(0x0101, I_T0, I_T0, OC_ORI)); testPrint(create_rtype_hex(FC_SUB, 0x0002, I_T0, I_T1, I_T2, OC_SUB)); testPrint(create_itype_hex(0xD070, I_T0, I_T1, OC_SW)); testPrint(create_specialtype_hex(OC_STOP)); return 0; }
/* JAL */ void test_jal() { int pcSaved; word w; Instruction* instruction; pc = 0x00000000; pcSaved = pc; test_execute(create_jtype_hex(0x0001, OC_JAL)); assert(RA == pcSaved + 4); assert(pc == 4); /* The following test is executed manually as the desired pc is outside the memory, * i.e. the test needs to bypass actually storing the instruction in the memory. */ initialize(); pc = 0xAF000000; pcSaved = pc; w = create_jtype_hex(0x0001, OC_JAL); instruction = (Instruction *) &w; pc += 4; operations[instruction->i.opcode].operation(instruction); assert(RA == pcSaved + 4); assert(pc == 0xA0000004); }
/* Assembles the given parts of an special-type instruction into a single word*/ word create_specialtype_hex(unsigned short opcode) { return create_jtype_hex(0x0000, opcode); }