2008年11月23日

Blackfin汇编语言之程序流程控制


Blackfin常用指令均摘录自blackfin编程参考手册,以方便查阅。

Blackfin流程控制指令有:

1. jump
2. if CC jump
3. call
4. rts, rti, rtx, rtn, rte
5. lsetup, loop

分别简介之。

* jump

General Form
JUMP (destination_indirect)
JUMP (PC + offset)
JUMP offset
JUMP.S offset
JUMP.L offset

Syntax
JUMP ( Preg ) ;
/*indirect to an absolute (not PC-relative)address(a)*/
JUMP ( PC + Preg ) ; /* PC-relative, indexed (a)*/
JUMP pcrel25m2 ; /* PC-relative, immediate (a) or (b)*/
JUMP.S pcrel13m2 ; /*PC-relative, immediate, short (a)*/
JUMP.L pcrel25m2 ; /* PC-relative, immediate, long (b)*/
JUMP user_label ;
/* user-defined absolute address label,resolved by the
assembler/linker to the appropriate PC-relative
instruction (a) or (b) */

Syntax Terminology
Preg: P5–0, SP, FP
pcrelm2: undetermined 25-bit or smaller signed, even
relative offset, with a range of –16,777,216
through 16,777,214 bytes
(0xFF00 0000 to 0x00FF FFFE)
pcrel13m2: 13-bit signed, even relative offset, with a
range of –4096 through 4094 bytes (0xF000 to
0x0FFE)
pcrel25m2: 25-bit signed, even relative offset, with a
range of –16,777,216 through 16,777,214 bytes
(0xFF00 0000 to 0x00FF FFFE)
user_label: valid assembler address label, resolved by
the assembler/linker to a valid PC-relative offset

注:1(a)16bit指令长度,(b)32bit指令长度
(bp)Branch Prediction
2。跳转地址必须偶地址对齐(16bit-address)

* if cc jump

General Form
IF CC JUMP destination
IF !CC JUMP destination

Syntax
IF CC JUMP pcrel11m2 ;
/* branch if CC=1, branch predicted as not taken (a)*/
IF CC JUMP pcrel11m2 (bp) ;
/* branch if CC=1, branch predicted as taken (a) */
IF !CC JUMP pcrel11m2 ;
/* branch if CC=0, branch predicted as not taken (a)*/
IF !CC JUMP pcrel11m2 (bp) ;
/* branch if CC=0, branch predicted as taken (a) */
IF CC JUMP user_label ;
/*user-defined absolute address label, resolved by the
assembler/linker to the appropriate PC-relative
instruction (a) */
IF CC JUMP user_label (bp) ;
/* user-defined absolute address label, resolved by the
assembler/linker to the appropriate PC-relative
instruction (a) */
IF !CC JUMP user_label ;
/* user-defined absolute address label, resolved by the
assembler/linker to the appropriate PC-relative
instruction(a) */
IF !CC JUMP user_label (bp) ;
/* user-defined absolute address label, resolved by the
assembler/linker to the appropriate PC-relative
instruction (a) */

Syntax Terminology
pcrel11m2: 11-bit signed even relative offset, with a
range of –1024 through 1022 bytes (0xFC00 to 0x03FE)
this value can optionally be replaced with an
address label that is evaluated and replaced during
linking.
user_label: valid assembler address label, resolved by
the assembler/linker to a valid PC-relative offset

* call

General Form
CALL (destination_indirect)
CALL (PC + offset)
CALL offset

Syntax
CALL ( Preg ) ;
/*indirect to an absolute (not PC-relative) address (a)*/
CALL ( PC + Preg ) ; /* PC-relative, indexed (a) */
CALL pcrel25m2 ; /* PC-relative, immediate (b) */
CALL user_label ; /*user-defined absolute address label,
resolved by the assembler/linker to the appropriate
PC-relative instruction (a) or (b) */

Syntax Terminology
Preg: P5–0, SP, FP
pcrel25m2: 25-bit signed, even, PC-relative offset; can
be specified as a symbolic address label, with a
range of –16,777,216 through 16,777,214 (0xFF00 0000
to 0x00FF FFFE) bytes.
user_label: valid assembler address label, resolved by
the assembler/linker to a valid PC-relative offset

* RTS, RTI, RTX, RTN, RTE (Return)

General Form
RTS, RTI, RTX, RTN, RTE

Syntax
RTS ; // Return from Subroutine (a)
RTI ; // Return from Interrupt (a)
RTX ; // Return from Exception (a)
RTN ; // Return from NMI (a)
RTE ; // Return from Emulation (a)

Types of Return Instruction



* LSETUP, LOOP

General Form
There are two forms of this instruction. The first is:

LOOP loop_name loop_counter
LOOP_BEGIN loop_name
LOOP_END loop_name

The second form is:

LSETUP (Begin_Loop, End_Loop)Loop_Counter

Syntax
For Loop0

LOOP loop_name LC0 ; /* (b) */
LOOP loop_name LC0 = Preg ; /*autoinitialize LC0 (b)*/
LOOP loop_name LC0 = Preg >> 1 ; /* autoinit LC0(b) */
LOOP_BEGIN loop_name ;
/* define the 1st instruction of loop(b)*/
LOOP_END loop_name ;
/* define the last instruction of the loop (b) */
/* use any one of the LOOP syntax versions with a
LOOP_BEGIN and a LOOP_END instruction. The name of the
loop (“loop_name” in the syntax) relates the three
instructions together. */
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC0 ; /* (b) */
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC0 = Preg ;
/* autoinitialize LC0 (b) */
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC0 = Preg >> 1 ;
/* autoinitialize LC0 (b) */

For Loop1

LOOP loop_name LC1 ; /* (b) */
LOOP loop_name LC1 = Preg ; /* autoinitialize LC1 (b)*/
LOOP loop_name LC1 = Preg >> 1;/*autoinitialize LC1 (b)*/
LOOP_BEGIN loop_name ;
/* define the first instruction of the loop (b) */
LOOP_END loop_name ;
/* define the last instruction of the loop (b) */
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC1 ; /* (b) */
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC1 = Preg ;
/* autoinitialize LC1 (b) */
LSETUP ( pcrel5m2 , lppcrel11m2 ) LC1 = Preg >> 1 ;
/* autoinitialize LC1 (b) */

Syntax Terminology
Preg: P5?b>C0 (SP and FP are not allowed as the source
register for this instruction.)
pcrel5m2: 5-bit unsigned, even, PC-relative offset; can
be replaced by a symbolic label. The range is 4 to 30.
lppcrel11m2: 11-bit unsigned, even, PC-relative offset
for a loop; can be replaced by a symbolic label. The
range is 4 to 2046 (0x0004 to 0x07FE).
loop_name: a symbolic identifier

Blackfin包含两组寄存器用于硬件循环:
Loop_Top (LTx): LT0,LT1
Loop_Bottom (LBx): LB0,LB1
Loop_Count (LCx): LC0,LC1

没有评论: