From baa7caf7c61612815f94121b3897f82ba0b3b6b7 Mon Sep 17 00:00:00 2001 From: daviduwu9 Date: Mon, 13 Sep 2021 20:55:05 +0930 Subject: [PATCH] implementated a more maintainable solution for mov instruction with I operand encoding --- src/common.h | 1 - src/encoder.c | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common.h b/src/common.h index 6fe9925..d393bff 100644 --- a/src/common.h +++ b/src/common.h @@ -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) diff --git a/src/encoder.c b/src/encoder.c index 18f8fe8..307a768 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -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