First of all... I am a total noob with assembly. I understand almost nothing. But this code which you are gonna see below works fine in Visual Studio. I just need to compile this to .o file using a simple g command.
g -o fileName.o filename.cpp
I need to translate assembly code written inside brackets {}
to assembly written inside parentheses ()
. When I am trying to compile below code it crashes. Compiler suggest to use (
instead of {
unsigned char decode5a[0x0dac];
unsigned char* srcbuf = new unsigned char[4000];
m_image = new unsigned char[4000];
unsigned char* dstbuf = m_image;
__asm
{
lea eax, decode5a
push srcbuf
push dstbuf
call eax
add esp, 8
}
I tried something like that but it crash also. I think I am passing variable incorrectly.
__asm__(
"lea eax, decode5a \n
push srcbuf \n
push dstbuf \n
call eax \n
add esp, 8 \n
");
CodePudding user response:
Here's how you would write that in gcc extended inline assembly, but this still may not work depending on what the function does. In particular, any registers modified by the function have to be listed in the clobbers.
__asm__(
"push %1\n"
"push %2\n"
"call *%0\n"
"add $8, %%esp \n"
: : "r"(decode5a), "r"(srcbuf), "r"(dstbuf)
: "eax", "memory");