示例#1
0
void test_instruction_rr_3(void) {
    Instruction* i = new_instruction_rr(op("and", AND), 0, 4);
    TEST_ASSERT_EQUAL_INT(I_TYPE_RR, i->type);
    TEST_ASSERT_EQUAL_INT_MESSAGE(0, i->rD, "Incorrect rD value");
    TEST_ASSERT_EQUAL_INT_MESSAGE(4, i->rS, "Incorrect rS value");
    free(i);
}
示例#2
0
void test_assemble_ADD(void) {
    test_reset();
    Instruction* i = new_instruction_rr(op("add", ADD), 3, 2);

    assemble_instruction(i, &ptr_copy);
    uint16_t array_compare[] = {0x0113, 0};
    TEST_ASSERT_EQUAL_HEX16_ARRAY(array_compare, data, 2);
    free(i);
}
示例#3
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);
}
示例#4
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);
}