Beispiel #1
0
void test_shift_selector(void) {
    Instruction* i =
        new_instruction_ri(op("shl", SHL), 4, addr_from_immediate(5));
    TEST_ASSERT_EQUAL_INT_MESSAGE(5 << 3 | 4, build_shift_selector(i),
                                  "Incorrect selector for shli");
    free(i);
}
Beispiel #2
0
void test_jmp_selector(void) {
    Instruction* i =
        new_instruction_jmpi(op("jmp", JMP), addr_from_immediate(34), OS);
    TEST_ASSERT_EQUAL_INT_MESSAGE(OS << 3, build_jmp_selector(i),
                                  "Incorrect selector for jmp");
    free(i);
}
Beispiel #3
0
void test_mem_selector(void) {
    Instruction* i = new_instruction_memi(
        op("st", ST), 3, 2, addr_from_immediate(456), false, true);
    TEST_ASSERT_EQUAL_INT_MESSAGE(1 << 6 | 2 << 3 | 3, build_mem_selector(i),
                                  "Incorrect selector for memi");
    free(i);
}
Beispiel #4
0
void test_assemble_SHRI(void) {
    test_reset();
    Instruction* i =
        new_instruction_ri(op("shr", SHR), 4, addr_from_immediate(3));
    assemble_instruction(i, &ptr_copy);
    uint16_t array_compare[] = {0x9a04, 0x0003, 0};
    TEST_ASSERT_EQUAL_HEX16_ARRAY(array_compare, data, 2);
    free(i);
}
Beispiel #5
0
void test_assemble_SUBI(void) {
    test_reset();
    Instruction* i =
        new_instruction_ri(op("sub", SUB), 2, addr_from_immediate(0xf34d));
    assemble_instruction(i, &ptr_copy);
    uint16_t array_compare[] = {0x8202, 0xf34d, 0};
    TEST_ASSERT_EQUAL_HEX16_ARRAY(array_compare, data, 3);
    free(i);
}
Beispiel #6
0
void test_instruction_jmpi_3(void) {
    Instruction* i =
        new_instruction_jmpi(op("jmp", JMP), addr_from_immediate(23), EQ);
    TEST_ASSERT_EQUAL_INT(I_TYPE_JMPI, i->type);
    TEST_ASSERT_EQUAL_INT_MESSAGE(23, i->address->immediate,
                                  "Incorrect Immediate");
    TEST_ASSERT_EQUAL_INT_MESSAGE(EQ, i->cc, "Incorrect Condition code");
    TEST_ASSERT_EQUAL_INT_MESSAGE(JMPI, i->op_type, "Incorrect opcode");
    free(i);
}
Beispiel #7
0
void test_instruction_ri_3(void) {
    Instruction* i =
        new_instruction_ri(op("add", ADD), 5, addr_from_immediate(345));
    TEST_ASSERT_EQUAL_INT(I_TYPE_RIMM, i->type);
    TEST_ASSERT_EQUAL_INT_MESSAGE(ADDI, i->op_type, "Incorrect opcode");
    TEST_ASSERT_EQUAL_INT_MESSAGE(5, i->rD, "Incorrect rD value");
    TEST_ASSERT_EQUAL_INT_MESSAGE(345, i->address->immediate,
                                  "Incorrect immediate");
    free(i);
}
Beispiel #8
0
void test_reg_selector(void) {
    Instruction* i = new_instruction_rr(op("sub", SUB), 4, 3);
    uint8_t      sel = build_reg_selector(i);
    TEST_ASSERT_EQUAL_INT(0b00011100, sel);
    free(i);
    Instruction* i2 =
        new_instruction_ri(op("add", ADD), 3, addr_from_immediate(45));
    sel = build_reg_selector(i2);
    TEST_ASSERT_EQUAL_INT(0b00000011, sel);
    free(i2);
}
Beispiel #9
0
void test_instruction_memi_5(void) {
    Instruction* i = new_instruction_memi(
        op("st", ST), 3, 4, addr_from_immediate(2567), false, true);
    TEST_ASSERT_EQUAL_INT(I_TYPE_MEMI, i->type);
    TEST_ASSERT_EQUAL_INT_MESSAGE(3, i->rD, "Incorrect rD value");
    TEST_ASSERT_EQUAL_INT_MESSAGE(4, i->rS, "Incorrect rS value");
    TEST_ASSERT_EQUAL_INT_MESSAGE(M_DISP, i->flags, "Incorrect MEM flags");
    TEST_ASSERT_EQUAL_INT_MESSAGE(2567, i->address->immediate,
                                  "Incorrect Immediate");
    TEST_ASSERT_EQUAL_INT_MESSAGE(STI, i->op_type, "Incorrect opcode");
    free(i);
}
Beispiel #10
0
void test_instruction_length(void) {
    Instruction* rr = new_instruction_rr(op("add", ADD), 3, 2);
    Instruction* ri =
        new_instruction_ri(op("xor", XOR), 0, addr_from_immediate(234));
    Instruction* memi = new_instruction_memi(
        op("ld", LD), 3, 4, addr_from_immediate(1234), false, false);
    Instruction* shift =
        new_instruction_ri(op("shl", SHL), 3, addr_from_immediate(2));
    Instruction* mov_special =
        new_instruction_ri(op("mov", MOV), 3, addr_from_immediate(24));
    Instruction* mov_general =
        new_instruction_ri(op("mov", MOV), 5, addr_from_immediate(1456));
    Instruction* jmpi =
        new_instruction_jmpi(op("jmp", JMP), addr_from_immediate(34), AL);
    TEST_ASSERT_EQUAL_INT_MESSAGE(2, instruction_length(rr),
                                  "Incorrect RR instruction length");
    TEST_ASSERT_EQUAL_INT_MESSAGE(4, instruction_length(ri),
                                  "Incorrect RI instruction length");
    TEST_ASSERT_EQUAL_INT_MESSAGE(4, instruction_length(memi),
                                  "Incorrect MemI instruction length");
    TEST_ASSERT_EQUAL_INT_MESSAGE(4, instruction_length(shift),
                                  "Incorrect Shift instruction length");
    TEST_ASSERT_EQUAL_INT_MESSAGE(2, instruction_length(mov_special),
                                  "Incorrect Special movi instruction length");
    TEST_ASSERT_EQUAL_INT_MESSAGE(4, instruction_length(mov_general),
                                  "Incorrect General movi instruction length");
    TEST_ASSERT_EQUAL_INT_MESSAGE(4, instruction_length(jmpi),
                                  "Incorrect JmpI instruction length");
    free(rr);
    free(ri);
    free(memi);
    free(shift);
    free(mov_special);
    free(mov_general);
    free(jmpi);
}