diff options
Diffstat (limited to 'executor/x86_64')
-rw-r--r-- | executor/x86_64/asm.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/executor/x86_64/asm.c b/executor/x86_64/asm.c index cf56b69..f57f117 100644 --- a/executor/x86_64/asm.c +++ b/executor/x86_64/asm.c @@ -34,6 +34,10 @@ static u8 rex_rm(AsmPtr *dst, Reg64 src) { return rex_sib(dst->base, src); } +static i32 abs_i32(i32 num) { + return num >= 0 ? num : -num; +} + #ifdef DEBUG #include <stdarg.h> #include <string.h> @@ -122,10 +126,6 @@ static const char* reg64_to_str(Reg64 reg) { return NULL; } -static i32 abs(i32 num) { - return num >= 0 ? num : -num; -} - static const char* asm_ptr_to_string(AsmPtr *self) { const char *buf = (const char*)(asm_debug_str_buffer + asm_debug_str_buffer_index); asm_debug_str_append("QWORD PTR ["); @@ -140,7 +140,7 @@ static const char* asm_ptr_to_string(AsmPtr *self) { asm_debug_str_append(" - "); else asm_debug_str_append(" + "); - asm_debug_str_append_num(abs(self->disp)); + asm_debug_str_append_num(abs_i32(self->disp)); } asm_debug_str_append("]"); return buf; @@ -293,10 +293,6 @@ void asm_nop(Asm *self) { ins_end(self, "nop"); } -static i32 abs_i32(i32 value) { - return value >= 0 ? value : -value; -} - /* TODO: Implement 1 and 2 byte displacement? There has to be at least 6 bytes left in the asm buffer before calling this function. @@ -626,7 +622,7 @@ void asm_jz(Asm *self, i32 relative) { in a maximum instruction pointer size of 16 bits */ ins_start(self); - if(abs(relative - 2) <= INT8_MAX) { + if(abs_i32(relative - 2) <= INT8_MAX) { relative -= 2; *self->code_it++ = 0x74; *self->code_it++ = (i8)relative; @@ -659,7 +655,7 @@ void asm_jmp(Asm *self, i32 relative) { in a maximum instruction pointer size of 16 bits */ ins_start(self); - if(abs(relative - 2) <= INT8_MAX) { + if(abs_i32(relative - 2) <= INT8_MAX) { relative -= 2; *self->code_it++ = 0xEB; *self->code_it++ = (i8)relative; |