Skip to content

Commit

Permalink
Resolved clash between MR and RM identities
Browse files Browse the repository at this point in the history
The `MR` and `RM` identies are very very similar, they both use
the same operand type - namely registers and also what Intel refe-
rers as `m` (memory) locations. Due to the `MR` identity being put
before the `RM` identity in `encoder.h`'s `enum enc_ident` enumeration,
the assembler has always had a tendency to use the `MR` encoder enum
identity when a register and memory location is expressed. This is very
problematic when the assembler matches the operand types with some
instructions that *don't support* the `MR` identity, causing an op-
code error to be thrown.

Therefore to prevent the confusing behavior, we'll need to manually override
this behavior by *manually* adding a if condition to change it when
able.
  • Loading branch information
cheng-alvin committed Jan 2, 2025
1 parent dcbcf92 commit a9ac3f4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libjas/instruction.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ instr_encode_table_t instr_get_tab(instruction_t instr) {
// clang-format on

enum enc_ident ident = op_ident_identify(operand_list);
if (ident == ENC_MR && op_r(operand_list[0])) ident = ENC_RM;
if (instr.instr == INSTR_MOV) {
if (ident == ENC_MI) ident = ENC_OI;
if (ident == ENC_I) ident = ENC_O;
}

for (uint8_t j = 0; CURR_TABLE.opcode_size; j++)
if (CURR_TABLE.ident == ident) return CURR_TABLE;

Expand Down

0 comments on commit a9ac3f4

Please sign in to comment.