/* ORI */ void test_ori() { test_execute(create_itype_hex(0xFFFF, I_T0, I_T1, OC_ORI)); assert((T0 == 0xFFFF) | (T0 == T1)); test_execute(create_itype_hex(0x00FF, I_T0, I_T1, OC_ORI)); assert((T0 == 0xFF) | (T0 == T1)); }
/* LUI */ void test_lui() { test_execute(create_itype_hex(0xFFFF, I_T0, I_ZERO, OC_LUI)); assert(T0 == 0xFFFF0000); test_execute(create_itype_hex(0x0001, I_T0, I_ZERO, OC_LUI)); assert(T0 == 0x00010000); }
/* ORI */ void test_ori() { T2 = 0x0000A005; test_execute(create_itype_hex(0xA099, I_T0, I_T2, OC_ORI)); assert(T0 == (0x0000A005 | 0xA099)); test_execute(create_itype_hex(0xFFFF, I_T0, I_T2, OC_ORI)); assert(T0 == 0x0000FFFF); }
/* ORI */ void test_ori() { T0 = 0x0000A0A0; test_execute(create_itype_hex(0x0A0A, I_T2, I_T0, OC_ORI)); assert(T2 == 0x0000AAAA); T0 = 0x0000F0F0; test_execute(create_itype_hex(0x0000, I_T2, I_T0, OC_ORI)); assert(T2 == 0x0000F0F0); }
/* ORI */ void test_ori() { T0 = 0xFFFF0000; test_execute(create_itype_hex(0x0000FFFF, I_T0, I_T0, OC_ORI)); assert(T0 == 0xFFFFFFFF); T0 = 0xF0F0F0F0; test_execute(create_itype_hex(0x0000FFF0, I_T0, I_T0, OC_ORI)); assert(T0 == 0xF0F0FFF0); }
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; }
/* LW */ void test_lw() { word location1 = 0x00001000; word w = 0xFFFFFFFF; storeWord(w, location1); T1 = location1; test_execute(create_itype_hex(0x0000, I_T0, I_T1, OC_LW)); assert(T0 == w); w =0x12345678; storeWord(w, location1 + 0x0001); T1 = location1; test_execute(create_itype_hex(0x0001, I_T0, I_T1, OC_LW)); assert(T0 == w); }
/* printf memory */ void test_printf_memory_write() { byte buf[4]; word w = 'a' << 24 | 'b'<<16 | 'c'<<8 | '\n'; /* set up a testfile in write mode */ FILE *file = fopen(TESTFILE,"w"); assert(file); /* redirect output of fprintf memory to this file */ outputStream = file; /* write the string "abc" to fprintf */ S2 = FPRINTF_MEMORY_LOCATION; S1 = w; test_execute(create_itype_hex(0x000, I_S1, I_S2, OC_SW)); fclose(file); /* check if the output was "abc" */ file = fopen(TESTFILE,"r"); assert(file); fread(buf, 1, 4, file); fclose(file); assert(buf[0] == 'a'); assert(buf[1] == 'b'); assert(buf[2] == 'c'); assert(buf[3] == '\n'); }
/* SW */ void test_sw() { word location1 = 0x00001000; word location2 = 0x00001004; word w = 0xFFFFFFFF; T0 = w; T1 = location1; test_execute(create_itype_hex(0x0000, I_T0, I_T1, OC_SW)); assert(loadWord(location1) == w); w =0x12345678; T0 = w; T1 = location2; test_execute(create_itype_hex(0xFFFC, I_T0, I_T1, OC_SW)); assert(loadWord(location1) == w); }
/* LW */ void test_lw() { word location1 = 0x00001230; word location2 = 0x00001234; word w = 0xFFFFFFFF; storeWord(w, location1); T1 = location1; test_execute(create_itype_hex(0x0000, I_T0, I_T1, OC_LW)); assert(T0 == w); w = 0x87654321; storeWord(w, location2); T1 = location1; test_execute(create_itype_hex(0x0004, I_T0, I_T1, OC_LW)); assert(T0 == w); }
/* LW */ void test_lw() { word location = 0x000000FF; word save = 0xDEADBEEF; storeWord(save, location); T1 = location; test_execute(create_itype_hex(0x0000, I_T0, I_T1, OC_LW)); assert(T0 == save); }
/* ADDI */ void test_addi() { test_execute(create_itype_hex(0xFFFF, I_T0, I_ZERO, OC_ADDI)); assert(T0 == -1); test_execute(create_itype_hex(1, I_T0, I_T0, OC_ADDI)); assert(T0 == 0); test_execute(create_itype_hex(0xFFFF, I_T0, I_ZERO, OC_ADDI)); assert(T0 == -1); test_execute(create_itype_hex(0xFFFF, I_T0, I_T0, OC_ADDI)); assert(T0 == -2); test_execute(create_itype_hex(3, I_T0, I_ZERO, OC_ADDI)); assert(T0 == 3); test_execute(create_itype_hex(1, I_T1, I_T0, OC_ADDI)); assert(T0 == 3); assert(T1 == 4); }