Skip to content

Commit

Permalink
[i8051] Check invalid instruction MOV A,ACC
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed May 14, 2024
1 parent 6ff2ea5 commit 0bbc98f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/asm_i8051.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ void AsmI8051::encodeOperand(AsmInsn &insn, AddrMode mode, const Operand &op) co
case M_NOTAD:
if (op.val16 >= 0x100)
insn.setErrorIf(op, mode == M_ADR8 ? OVERFLOW_RANGE : NOT_BIT_ADDRESSABLE);
if (TABLE.invalidDirect(insn.opCode(), op.val16))
insn.setErrorIf(op, OPERAND_NOT_ALLOWED);
insn.emitOperand8(op.val16);
break;
default:
Expand Down
5 changes: 4 additions & 1 deletion src/dis_i8051.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ void DisI8051::decodeRReg(DisInsn &insn, StrBuffer &out, AddrMode mode) const {

void DisI8051::decodeAddress(DisInsn &insn, StrBuffer &out, AddrMode mode) const {
if (mode == M_ADR8) {
outAbsAddr(out, insn.readByte(), 8);
const auto addr = insn.readByte();
if (TABLE.invalidDirect(insn.opCode(), addr))
insn.setErrorIf(out, OPERAND_NOT_ALLOWED);
outAbsAddr(out, addr, 8);
} else if (mode == M_ADR11) {
const auto val8 = insn.readByte();
auto addr = (insn.address() + insn.length()) & 0xF800;
Expand Down
5 changes: 5 additions & 0 deletions src/table_i8051.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ Error TableI8051::searchOpCode(CpuType cpuType, DisInsn &insn, StrBuffer &out) c
return insn.getError();
}

bool TableI8051::invalidDirect(Config::opcode_t opc, uint16_t addr) const {
// MOV A, ACC is not a valid instruction
return opc == 0xE5 && addr == 0xE0;
}

const /*PROGMEM*/ char *TableI8051::listCpu_P() const {
return TEXT_CPU_I8051;
}
Expand Down
2 changes: 2 additions & 0 deletions src/table_i8051.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct TableI8051 final : InsnTable<CpuType> {

Error searchName(CpuType, AsmInsn &insn) const;
Error searchOpCode(CpuType, DisInsn &insn, StrBuffer &out) const;

bool invalidDirect(Config::opcode_t opc, uint16_t addr) const;
};

extern const TableI8051 TABLE;
Expand Down
1 change: 1 addition & 0 deletions test/test_asm_i8051.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ static void test_direct() {
TEST("XCH A,0C6H", 0xC5, 0xC6);
TEST("MOV A,0E6H", 0xE5, 0xE6);
ERRT("MOV A,101H", OVERFLOW_RANGE, "101H", 0xE5, 0x01);
ERRT("MOV A,0E0H", OPERAND_NOT_ALLOWED, "0E0H", 0xE5, 0xE0);
TEST("MOV 0F6H,A", 0xF5, 0xF6);
ERRT("MOV 102H,A", OVERFLOW_RANGE, "102H,A", 0xF5, 0x02);

Expand Down
1 change: 1 addition & 0 deletions test/test_dis_i8051.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ static void test_direct() {
TEST("XCH", "A, 0C6H", 0xC5, 0xC6);
TEST("MOV", "A, 0E6H", 0xE5, 0xE6);
TEST("MOV", "0F6H, A", 0xF5, 0xF6);
ERRT("MOV", "A, 0E0H", OPERAND_NOT_ALLOWED, "0E0H", 0xE5, 0xE0);
NMEM("MOV", "A, 00H", "00H", 0xE5);
NMEM("MOV", "00H, A", "00H, A", 0xF5);

Expand Down

0 comments on commit 0bbc98f

Please sign in to comment.