simon987 / Much-Assembly-Required

Assembly programming game
GNU General Public License v3.0
930 stars 87 forks source link

SAL instruction will throw an error while assembling #185

Closed kevinramharak closed 5 years ago

kevinramharak commented 5 years ago

This is because in the ADD instruction set the instruction gets ignored if its an alias for another instruction.

// DefaultInstructionSet.java
public void add(Instruction instruction) {
        if (instructionMap.containsKey(instruction.getOpCode())) {
            LogManager.LOGGER.fine(instruction.getMnemonic() + " instruction is an alias for " +
                    instructionMap.get(instruction.getOpCode()).getMnemonic());
        } else {
            instructionMap.put(instruction.getOpCode(), instruction);

        }
}

But the assembler uses the mnemonic's inside the instructionMap to encode the instructions:

// Assembler.java
/// ... more code
} else {
            //No operand

            //Encode instruction
            //Get instruction by name
            instructionSet.get(mnemonic).encode(out, currentLine);
        }

I found it while trying to figure out how to alias some of the SETcc instructions as some of those instructions are aliases as well.

simon987 commented 5 years ago

Good catch, I'll push a fix when I come back from work

kevinramharak commented 5 years ago

[01/15 20:32:34:815] [SEVERE] Unknown mnemonic "SHL"@2 The current code will overwrite SAL with the SHL instruction. I am not what a simple implementation woul be that works for the assembler and the cpu. Maybe have an alias slot in the instruction class? Or rethink the instruction map to a map that does not replace opcodes when a new one is added with the same opcode. What about a mnemonic to instruction hashmap? The CPU only needs to know about opcodes and retrieve the correct instruction while the assembler can use a different map to find an instruction. This will keep most of the current logic the same.