Branching in SH-4 Inline Assembly (Windows CE 5.0)
You can define a branch instruction in SH-4 inline assembly as a fixed displacement or as a jump to a targeted label.
If a label is used, the label must be defined within a __asm string in the current function. The __asm label must be isolated in its own __asm block.
The distance from a label reference to its definition must fit within the displacement field of the corresponding branch instruction.
Branch with Fixed Displacement
The following code example demonstrates how to use displacement branch instructions within __asm statements.
__asm(
"sett ; set T bit\n"
"bf 6 ; branch to print FAIL if not set\n"
"jsr @R6 ; print PASS\n"
"nop ; delay slot\n"
"bra 4 ; branch using displacement\n"
"nop ; delay slot\n"
"jsr @R6 ; print PASS\n"
"nop ; delay slot\n"
,"PASS\n" // argument #1 (R4)
,"FAIL\n" // argument #2 (R5)
,printf // argument #3 (R6)
);
Branch to Labeled Statement
The following code example demonstrates how to use labels in branch instructions within __asm statements.
#include <stdio.h>
void main()
{
__asm(
"sett ; set T bit\n"
"bf lab1 ; branch to print FAIL if not set\n"
"jsr @R5 ; print PASS\n"
"nop ; delay slot\n"
"bra lab2 ; branch using label\n"
"nop ; delay slot"
,"PASS\n"
,printf
);
__asm(
"lab1: ; isolate label"
);
__asm(
"jsr @R5 ; print FAIL\n"
"nop ; delay slot"
,"FAIL\n"
,printf
);
__asm(
"lab2:"
);
}
See Also
SH-4 Inline Assembly Language | SH-4 Inline Assembly Code Examples
Send Feedback on this topic to the authors