When I run this example:
#include <stdio.h>
#include <AsmJit.h>
using namespace AsmJit;
void doSomething(int a, int b)
{
printf("a = %d, b = %d\n", a, b);
}
void main()
{
// create compiler
Compiler c;
// create a function to generate code for
EFunction* func = c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder0<int>());
// attempt to generate without prologue/epilogue
func->setHint(FUNCTION_HINT_NAKED, true);
// call doSomething(5, 10);
ECall* func_call = c.call(&doSomething);
func_call->setPrototype(CALL_CONV_DEFAULT, FunctionBuilder2<Void, int, int>());
GPVar var_a(c.newGP(VARIABLE_TYPE_INT32));
GPVar var_b(c.newGP(VARIABLE_TYPE_INT32));
c.mov(var_a, imm(5));
c.mov(var_b, imm(10));
func_call->setArgument(0, var_a);
func_call->setArgument(1, var_b);
// now finish and compile the function
c.endFunction();
CompiledWord word = function_cast<CompiledWord>(c.make());
doSomething(5, 10); // a = 5, b = 10
(*word)(); // a = -858993460, b = -858993460 <-- what's going on here?!?
}
I get strange values when doSomething is called from the generated assembly. Am I doing something wrong? And if so, how do I fix it?
Thanks!
Grant Posner