Skip to content

Commit

Permalink
implementated a more maintainable solution for mov instruction with I…
Browse files Browse the repository at this point in the history
… operand encoding
  • Loading branch information
davidywu9 committed Sep 13, 2021
1 parent 2a5cb47 commit baa7caf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#define MAX_UNSIGNED_8BIT 0xff
#define MAX_SIGNED_32BIT 0x7fffffff
#define MAX_UNSIGNED_32BIT 0xffffffff
#define MOVI 6

// set register length to 1 byte
#define SET_BYTE ~(reg16 | reg32 | reg64)
Expand Down
7 changes: 4 additions & 3 deletions src/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,20 @@ void encode_imm(struct instr *instruc) {
INSTR_TABLE[instruc->key].type == DATA_TRANSFER) {
if (instruc->cons > MAX_SIGNED_32BIT && (instruc->opd[0] & reg64)) {
if (instruc->cons != NEG64BIT) {
instruc->key = MOVI;
instruc->key++;
instruc->op_offset = 8;
}
}
if (IN_RANGE(instruc->cons, NEG32BIT + 1, NEG64BIT) &&
(instruc->opd[0] & reg64)) {
if (instruc->cons != NEG64BIT)
instruc->key = MOVI;
instruc->key++;
else
instruc->cons -= NEG32BIT;
instruc->reduced_imm = true;
}
if (instruc->key == MOVI)
if (INSTR_TABLE[instruc->key].name == mov &&
INSTR_TABLE[instruc->key].encode_operand == I)
instruc->rd_offset = instruc->opd[0] & VALUE_MASK;
}
// mask all bits except for the most significant byte
Expand Down

0 comments on commit baa7caf

Please sign in to comment.