mov instruction generation question

73 views
Skip to first unread message

itre...@gmail.com

unread,
May 9, 2011, 2:06:17 PM5/9/11
to asmjit-dev
Hello all—

I'm just getting started with AsmJit, and generate machine code at
all, and I've run into an issue I can't solve. I'm trying to
dereference a double pointer, so as to write a value into an array
slot, as it were. The problem is my move instructions aren't getting
generated simply as "mov", but rather as "movupd". Could anyone clue
me in? So far, I'm doing something like this:

c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder2<Void, long*,
long*>());
c.getFunction()->setHint(FUNCTION_HINT_NAKED, true);

// function arguments
GPVar stack(c.argGP(0));
GPVar memory(c.argGP(1)

c.add(ptr(stack), 8); // inc stack array by one long
GPVar tmp(c.newGP()); // tmp
c.mov(tmp, ptr(stack)); // first dereference
c.mov(ptr(tmp), imm(instr->arg.i)); // second dereference, tmp is
writeable location
...

AsmJit Debug
; Modified registers (3):
; GP : rcx, rsi, rdi
; MM :
; XMM:

L.0:
; Prolog
; Body
add [rdi], 8
*** ASSEMBLER ERROR: Illegal instruction (4).
movupd rcx, 0
L.1:
; Epilog
*** COMPILER ERROR: Illegal instruction (4).
Error making jit function (4).

Thanks in advance for any hints or tips. It's a great project, and I'm
going to have a lot of fun once I figure this out!

Petr Kobalíček

unread,
May 9, 2011, 2:36:47 PM5/9/11
to asmji...@googlegroups.com
Hi,

it's tricky, but I found your problem. When using memory operand and
immediate operand, it's needed to specify the memory operand size.
This matches the intel assembler syntax.

Your first mov is compiled correctly, because you use:

c.mov(tmp, ptr(stack));

But the behavior is different across 32-bit and 64-bit mode, because
register size is implicitly defined as sizeof(void*) - This matches
the mode used. You can correct this by using VARIABLE_TYPE_GPD /
VARIABLE_TYPE_GPQ / VARIABLE_TYPE_INTPTR, etc...

But your second mov is

c.mov(ptr(tmp), imm(instr->arg.i));

Translated to intel syntax: mov ptr [someReg], someNumber. No
assembler can't compile this, so you have to provide the type size,
for example try one of these

c.mov(byte_ptr(tmp), imm(instr->arg.i));
c.mov(word_ptr(tmp), imm(instr->arg.i));
c.mov(dword_ptr(tmp), imm(instr->arg.i));
c.mov(qword_ptr(tmp), imm(instr->arg.i));
c.mov(sysint_ptr(tmp), imm(instr->arg.i));

Hope that helps,

but anyway thanks for this report, I will fix some asserts to improve
the message generated by AsmJit.

Best regards
Petr Kobalicek

Reply all
Reply to author
Forward
0 new messages