I remember back in the day with the old borland DOS compiler you could do something like this:
asm { mov ax,ex etc etc... }
Is there a semi-platform independent way to do this now? I have a need to make a BIOS call, so if there was a way to do this without asm code, that would be equally useful to me.
We can write assembly program code inside c language program. In such case, all the assembly code must be placed inside asm{} block.
C macros offer a convenient way to insert assembly code into your source code, but they demand extra care because a macro expands into a single logical line. To create trouble-free macros, follow these rules: Enclose the __asm block in braces.
An assembly language is a low-level programming language designed for a specific type of processor. It may be produced by compiling source code from a high-level programming language (such as C/C++) but can also be written from scratch. Assembly code can be converted to machine code using an assembler.
Related: Does a compiler always produce an assembly code? - no, big mainstream C compilers that provide a complete toolchain often go straight to machine code, especially ones (unlike GCC) that only target a few ISAs / object file formats.
Using GCC
__asm__("movl %edx, %eax\n\t" "addl $2, %eax\n\t");
Using VC++
__asm { mov eax, edx add eax, 2 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With