Jumping to Labels

Like an ordinary C label, a label in an __asm block is visible (has scope) throughout the function in which it is defined (not only in the block). Both assembly instructions and C goto statements can jump to labels inside or outside the __asm block.

Summary: Labels in __asm blocks have function scope and are not case sensitive.

Unlike C labels, labels defined in __asm blocks are not case sensitive, even when used in C statements. C labels are not case sensitive in an __asm block, either. (Outside an __asm block, a C label is case sensitive as usual.) The following do-nothing code shows all the permutations.

void func( void )

{

goto C_Dest; /* legal */

goto c_dest; /* error */

goto A_Dest; /* legal */

goto a_dest; /* legal */

__asm

{

jmp C_Dest ; legal

jmp c_dest ; legal

jmp A_Dest ; legal

jmp a_dest ; legal

a_dest: ; __asm label

}

C_Dest: /* C label */

return;

}

Don't use C library function names as labels in __asm blocks. For instance, you might be tempted to use exit as a label,

jne exit

.

.

.

exit:

; More __asm code follows

forgetting that exit is the name of a C library function. The code doesn't cause a compiler error, but it might cause a jump to the exit function instead of the desired location.

As in MASM programs, the dollar symbol ($) serves as the current location counter—a label for the instruction currently being assembled. In __asm blocks, its main use is to make long conditional jumps:

jne $+5 ; next instruction is 5 bytes long

jmp farlabel

; $+5

.

.

.

farlabel: