A while back, someone asked me how I would use the inline assembler feature of Visual C++ to implement conditional jumps to different parts of C code within the same function. Here is one example that I came up with:
#include <stdio.h> void main(int argc, char *argv[]) { int num = (argc > 1 && argv[1][0] == '2') ? 4 : 2; __asm { mov eax,offset null add eax,num null: jmp eax jmp one jmp two } one: printf("ONE\n"); goto end; two: printf("TWO\n"); end: 1; }
You can compile this program from the command line using cl asms.c (assuming you saved it under the name asms.c of course.) The program can be invoked with the optional parameter 2.
Please note that this style of inline assembler is Microsoft-specific. In GNU C, for instance, I do not believe that you can reference C labels from within your assembly language code. The instruction syntax is also quite different of course.