void testInstruction(){

    printf("Initializing instruction table...\n");
    initialize();
    printf("Inserting nop instruction at address 0...\n");
    insertInstruction(0, "nop", "");
    printf("Using fetchOpcode at address 0...\n");
    if(strcmp(fetchOpcode(0), "nop") != 0){
        printf("Failure!  The nop instruction was not fetched!\n");
    }
    else{
        printf("Success!  The nop instruction was fetched!\n");
    }

    printf("Inserting 'pop A' instruction at address 1...\n");
    insertInstruction(1, "pop", "A");
    printf("Fetching operand at address 1...\n");
    if(strcmp(fetchOperand(1), "A") !=0){
        printf("Failure!  The operand 'A' was not fetched.\n");
    }
    else{
        printf("Success!  The operand 'A' was fetched!\n");
    }
    printf("Attempting to insert a nop at an invalid address...\n");
    insertInstruction(-1, "nop", "");
    
    printf("\nAll tests concluded.\n");
}
Beispiel #2
0
const char* ARMv7DOpcode::disassemble(uint16_t*& currentPC)
{
    const char* result;
    fetchOpcode(currentPC);

    if (is32BitInstruction())
        result = reinterpret_cast<ARMv7D32BitOpcode*>(this)->doDisassemble();
    else
        result = reinterpret_cast<ARMv7D16BitOpcode*>(this)->doDisassemble();

    if (startingITBlock())
        m_ITConditionIndex = 0;
    else if (inITBlock() && (++m_ITConditionIndex >= m_ITBlocksize))
        endITBlock();

    return result;
}
unsigned int CPU::step()
{
    if (Q_UNLIKELY(m_paused))
    {
        return 0;
    }
    byte opcode = fetchOpcode(m_state.pc++);
    bool interrupted = false;

    if (Q_UNLIKELY(m_state.interrupt && m_state.int_enabled))
    {
        interrupted = true;
        m_state.halt_flag = false;
        m_state.int_enabled = false;
        m_state.interrupt = false;
        opcode = m_state.interrupt_opcode;
        m_state.interrupt_opcode = 0;
        m_state.pc--;
    }

    if (Q_LIKELY(!m_state.halt_flag))
    {

        for (auto opcodeDef : m_opcodes)
        {
            if (opcodeDef.isMatching(opcode))
            {
                auto clockCycles = executeOpcode(opcodeDef, opcode);
                return clockCycles;
            }
        }

    }
    else
    {
        return 0;
    }
    error((QString("Illegal instruction : 0x") + QString::number(opcode, 16) + "/" + QString::number(opcode, 2) +
           (interrupted ? " (interruption)" :  " (Address : 0x" + QString::number(m_state.pc - 1, 16) + ")")).toStdString());
}
Beispiel #4
0
void runProgram(){
    int pc = 0;
    char lastOp[OPCODE_SIZE];
    int haltHit = 0;
    while(!haltHit){
        if(strcmp(fetchOpcode(pc), "nop") == 0){
            pc = nop(pc);
        }
        if(strcmp(fetchOpcode(pc), "add") == 0){
            pc = add(pc);
        }

        if(strcmp(fetchOpcode(pc), "sub") == 0){
            pc = sub(pc);
        }

        if(strcmp(fetchOpcode(pc), "mult") == 0){
            pc = mult(pc);
        }
        if(strcmp(fetchOpcode(pc), "div") == 0){
            pc = divide(pc);
        }
        if(strcmp(fetchOpcode(pc), "get") == 0){
            pc = get(pc);
        }
        if(strcmp(fetchOpcode(pc), "put") == 0){
            pc = put(pc);
        }
        if(strcmp(fetchOpcode(pc), "push") == 0){
            pc = push(pc);
        }
        if(strcmp(fetchOpcode(pc), "pop") == 0){
            pc = pop(pc);
        }
        if(strcmp(fetchOpcode(pc), "not") == 0){
            pc = not(pc);
        }
        if(strcmp(fetchOpcode(pc), "and") == 0){
            pc = and(pc);
        }
        if(strcmp(fetchOpcode(pc), "or") == 0){
            pc = or(pc);
        }
        if(strcmp(fetchOpcode(pc), "tsteq") == 0){
            pc = testeq(pc);
        }
        if(strcmp(fetchOpcode(pc), "tstne") == 0){
            pc = testne(pc);
        }
        if(strcmp(fetchOpcode(pc), "tstlt") == 0){
            pc = testlt(pc);
        }
        if(strcmp(fetchOpcode(pc), "tstle") == 0){
            pc = testle(pc);
        }
        if(strcmp(fetchOpcode(pc), "tstgt") == 0){
            pc = testgt(pc);
        }
        if(strcmp(fetchOpcode(pc), "tstge") == 0){
            pc = testge(pc);
        }
        if(strcmp(fetchOpcode(pc), "j") == 0){
            pc = jump(pc);
        }
        if(strcmp(fetchOpcode(pc), "jf") == 0){
            pc = jf(pc);
        }
        if(strcmp(fetchOpcode(pc), "halt") == 0){
            haltHit = 1;
            pc = halt(pc);
        }
    }
}