From 1ac09dc704d199bb680b9b5939907ec828b5a61e Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Tue, 19 Oct 2021 13:41:29 -0700 Subject: Use disp8 when possible for memarg. --- main.c | 12 +++++------- test/test.sh | 1 + 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index ce1caa0..8f17d17 100644 --- a/main.c +++ b/main.c @@ -395,14 +395,12 @@ assemblemem(const Memarg* memarg, Rex rex, VarBytes prefix, VarBytes opcode, /* Case when we don't need sib */ if (memarg->index == ASM_NO_REG && memarg->scale == 0 && ((rm & 7) != 4)) { - if (memarg->disp.l == 0 && memarg->disp.c == 0) { - if ((rm & 7) == 5) { - mod = 1; - } else { - mod = 0; - } - } else { + if (memarg->disp.l != NULL || memarg->disp.c > INT8_MAX || memarg->disp.c < INT8_MIN) { mod = 2; + } else if (memarg->disp.c != 0 || (rm & 7) == 5) { + mod = 1; + } else { + mod = 0; } assemblevbytes(prefix); diff --git a/test/test.sh b/test/test.sh index 152ea2b..ecf5ce1 100644 --- a/test/test.sh +++ b/test/test.sh @@ -43,6 +43,7 @@ t "callq *%rax" t "callq *%r10" t "callq *(%r10)" t "movb %r11b, (%rsi, %r12, 1)" +t "mov %rdi, -0x60(%rbp)" for r in rax r10 do -- cgit v1.2.3