Skip to content

Commit

Permalink
Added experimental offsetted operand encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
cheng-alvin committed Jun 23, 2024
1 parent 5a86bc1 commit d75ea71
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions libjas/rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,16 @@ void rm(operand_t *op_arr, buffer_t *buf, instr_encode_table_t *instr_ref, enum
if (reg_needs_rex(*reg))
rex_insert(buf, REX_B);

uint8_t mr_mode;
uint8_t mr_mode = OP_MODRM_REG;

if (op_r(op_arr[1].type))
mr_mode = OP_MODRM_REG;
else if (op_m(op_arr[1].type))
// Experimental:
if (op_m(op_arr[1].type) && op_arr[1].offset == 0)
mr_mode = OP_MODRM_INDIRECT;

else {
err("Operand identity mismatch. (hint: displacements are not supported yet)");
return;
}
else if (op_arr[1].offset != 0)
mr_mode = OP_MODRM_DISP8;

buf_write_byte(buf, mr_mode << 6 | *reg << 3 | *rm);

if (op_arr[1].offset != 0)
buf_write_byte(buf, op_arr[1].offset);
}

0 comments on commit d75ea71

Please sign in to comment.