Translate embedded assembly for x64 support

I have a small inline build code written in my C code. Asm passes through the array and, if necessary, transfers values ​​from another array to the register. As a result, an interrupt is called. The code is similar to this:

cmp arrPointer[2],1h jne EXIT mov AX, shortArrPtr[2] EXIT: int 3h 

All this works in x86, but according to Microsoft: x64 does not support inline build. How can I translate all this for x64 support? I could not find the built-in compiler procedure to accomplish what I needed, and I could not figure out how to pass parameters to an external asm file.

+6
c assembly inline-assembly 64bit
source share
1 answer

I think you just came across why the built-in assembly is a pain in the ass - it is completely not portable (and not only between architectures, compilers often have different and incompatible syntax). Write an external assembly file and do what you need. Passing parameters to build procedures is exactly the same as passing them to C functions; just move the ad somewhere somewhere, and the call code (in C) will do it right. Then, follow the procedure in the external assembly file (be sure to abide by the calling convention) and export the appropriate symbol to link all the links correctly. Presto - working assembly!

Example, on request. I have not tried to compile or test this in any way, so this may not be 100%. Good luck.

myHeader.h:

 void *someOperation(void *parameter1, int parameter2); 

myAssemblyFile.s:

 .text .globl someOperation someOperation: add %rdx, %rcx mov %rcx, %rax ret .end 

mySourceCode.c:

 #include "myHeader.h" void someFunction(void) { void *arg1 = (void *)0x80001000; int arg2 = 12; void *returnValue; printf("Calling with %x %x\n", arg1, arg2); // call assembly function returnValue = someOperation(arg1, arg2); printf("Returned: %x\n", returnValue); } 
+6
source share

All Articles