<p>I remember back in the day with the old borland DOS compiler you could do something like this:</p>

<pre><code>asm {
 mov ax,ex
 etc etc...
}
</code></pre>

<p>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.</p>

[{'answer_id': 61344, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 3, 'selected': False, 'text': '<p>A good start would be reading this article which talk about inline assembly in C/C++:</p>\n\n<p><a href="http://www.codeproject.com/KB/cpp/edujini_inline_asm.aspx" rel="noreferrer">http://www.codeproject.com/KB/cpp/edujini_inline_asm.aspx</a></p>\n\n<p>Example from the article:</p>\n\n<pre><code>#include &lt;stdio.h&gt;\n\n\nint main() {\n    /* Add 10 and 20 and store result into register %eax */\n    __asm__ ( "movl $10, %eax;"\n                "movl $20, %ebx;"\n                "addl %ebx, %eax;"\n    );\n\n    /* Subtract 20 from 10 and store result into register %eax */\n    __asm__ ( "movl $10, %eax;"\n                    "movl $20, %ebx;"\n                    "subl %ebx, %eax;"\n    );\n\n    /* Multiply 10 and 20 and store result into register %eax */\n    __asm__ ( "movl $10, %eax;"\n                    "movl $20, %ebx;"\n                    "imull %ebx, %eax;"\n    );\n\n    return 0 ;\n}\n</code></pre>\n'}, {'answer_id': 61350, 'author': 'Niall', 'author_id': 6049, 'author_profile': 'https://Stackoverflow.com/users/6049', 'pm_score': 7, 'selected': True, 'text': '<p>Using <a href="http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html" rel="noreferrer">GCC</a></p>\n\n<pre><code>__asm__("movl %edx, %eax\\n\\t"\n        "addl $2, %eax\\n\\t");\n</code></pre>\n\n<p>Using <a href="http://msdn.microsoft.com/en-us/library/4ks26t93(VS.71).aspx" rel="noreferrer">VC++</a></p>\n\n<pre><code>__asm {\n  mov eax, edx\n  add eax, 2\n}\n</code></pre>\n'}, {'answer_id': 61745, 'author': 'Martin Del Vecchio', 'author_id': 5397, 'author_profile': 'https://Stackoverflow.com/users/5397', 'pm_score': 4, 'selected': False, 'text': '<p>In GCC, there\'s more to it than that.  In the instruction, you have to tell the compiler what changed, so that its optimizer doesn\'t screw up.  I\'m no expert, but sometimes it looks something like this:</p>\n\n<pre><code>    asm ("lock; xaddl %0,%2" : "=r" (result) : "0" (1), "m" (*atom) : "memory");\n</code></pre>\n\n<p>It\'s a good idea to write some sample code in C, then ask GCC to produce an assembly listing, then modify that code.</p>\n'}, {'answer_id': 63633, 'author': 'Mike Dimmick', 'author_id': 6970, 'author_profile': 'https://Stackoverflow.com/users/6970', 'pm_score': 2, 'selected': False, 'text': "<p>For Microsoft compilers, <em>inline</em> assembly is supported only for x86. For other targets you have to define the whole function in a separate assembly source file, pass it to an assembler and link the resulting object module.</p>\n\n<p>You're highly unlikely to be able to call into the BIOS under a protected-mode operating system and should use whatever facilities are available on that system. Even if you're in kernel mode it's probably unsafe - the BIOS may not be correctly synchronized with respect to OS state if you do so.</p>\n"}, {'answer_id': 66843327, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>use of <code>asm</code> or <code>__asm__</code> function ( in compilers have difference )</p>\n<p>also you can write fortran codes with <code>fortran</code> function</p>\n<pre><code>asm(&quot;syscall&quot;);\nfortran(&quot;Print *,&quot;J&quot;);\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/61341', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6062/']