Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #16433 - Use MOV opcode B8+ for MOV r64, <0x80000000 to 0xffffffff> #16572

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions libr/asm/p/asm_x86_nz.c
Original file line number Diff line number Diff line change
Expand Up @@ -1818,14 +1818,13 @@ static int opmov(RAsm *a, ut8 *data, const Opcode *op) {
data[l++] = immediate;
} else {
if (a->bits == 64 &&
((((op->operands[0].type & OT_QWORD) |
(op->operands[1].type & OT_QWORD)) &&
immediate < UT32_MAX) ||
((op->operands[0].type & OT_QWORD) &&
immediate >= 0xffffffff80000000 /* -0x80000000 */))) {
data[l++] = 0xc7;
data[l++] = 0xc0 | op->operands[0].reg;
imm32in64 = true;
((!(op->operands[0].type & OT_QWORD) && (op->operands[1].type & OT_QWORD) &&
immediate < UT32_MAX) ||
((op->operands[0].type & OT_QWORD) &&
(immediate <= ST32_MAX || immediate >= 0xffffffff80000000LL /* -0x80000000 */)))) {
data[l++] = 0xc7;
data[l++] = 0xc0 | op->operands[0].reg;
imm32in64 = true;
} else {
data[l++] = 0xb8 | op->operands[0].reg;
}
Expand All @@ -1835,7 +1834,8 @@ static int opmov(RAsm *a, ut8 *data, const Opcode *op) {
data[l++] = immediate >> 16;
data[l++] = immediate >> 24;
}
if (a->bits == 64 && immediate > UT32_MAX && !imm32in64) {
if (a->bits == 64 && (immediate > UT32_MAX || (op->operands[0].type & OT_QWORD)) &&
!imm32in64) {
data[l++] = immediate >> 32;
data[l++] = immediate >> 40;
data[l++] = immediate >> 48;
Expand Down
9 changes: 8 additions & 1 deletion test/db/asm/x86_64
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ aB "mov rax, 0x112233445566778899" 00
a "mov rax, 3" 48c7c003000000
a "mov rax, 33" 48c7c021000000
ad "mov rax, 0x7fffffff" 48c7c0ffffff7f
a "mov rax, 0x80000000" 48b80000008000000000
ad "movabs rax, 0x80000000" 48b80000008000000000
a "mov rax, 0xdeadbeef" 48b8efbeadde00000000
ad "movabs rax, 0xdeadbeef" 48b8efbeadde00000000
a "mov rax, 0xffffffff" 48b8ffffffff00000000
ad "movabs rax, 0xffffffff" 48b8ffffffff00000000
a "mov rax, 0x100000000" 48b80000000001000000
ad "movabs rax, 0x100000000" 48b80000000001000000
ad "mov rax, 0" 48c7c000000000
a "mov rax, -1" 48c7c0ffffffff
adB "mov rax, 0xffffffffffffffff" 48c7c0ffffffff
Expand Down Expand Up @@ -740,7 +748,6 @@ aB "mov qword[r12], rsp" 49892424
aB "mov qword[r8 + 0x20], rax" 49894020
aB "mov r12, qword[r12]" 4d8b2424
a "mov eax,r12d" 4489e0
ad "movabs rax, 0xdeadbeef" 48b8efbeadde00000000
ad "movabs r12, 1" 49bc0100000000000000
a "inc al" fec0
a "inc BYTE PTR [r12]" 41fe0424
Expand Down