Texas Instruments TMS320C2XX Calculator User Manual


 
Branches, Calls, and Returns
5-8
5.3 Branches, Calls, and Returns
Branches, calls, and returns break the sequential flow of instructions by trans-
ferring control to another location in program memory. A
branch
only transfers
control to the new location. A
call
also saves the return address (the address
of the instruction following the call) to the top of the hardware stack. Every
called subroutine or interrupt service routine is concluded with a
return
instruc-
tion, which pops the return address off the stack and back into the program
counter (PC).
The ’C2xx has two types of branches, calls, and returns:
Unconditional. An unconditional branch, call, or return is always
executed. The unconditional branch, call, and return instructions are de-
scribed in subsections 5.3.1, 5.3.2, and 5.3.3, respectively.
Conditional. A conditional branch, call, or return is executed only if certain
specified conditions are met. The conditional branch, call, and return
instructions are described in detail in Section 5.4,
Conditional Branches,
Calls, and Returns
, on page 5-10.
5.3.1 Unconditional Branches
When an unconditional branch is encountered, it is always executed. During
the execution, the PC is loaded with the specified program-memory address
and program execution begins at that address. The address loaded into the
PC may come from either the second word of the branch instruction or the low-
er sixteen bits of the accumulator.
By the time the branch instruction reaches the execute phase of the pipeline,
the next two instruction words have already been fetched. These two instruc-
tion words are flushed from the pipeline so that they are not executed, and then
execution continues at the branched-to address. The unconditional branch
instructions are B (branch) and BACC (branch to location specified by accu-
mulator).
5.3.2 Unconditional Calls
When an unconditional call is encountered, it is always executed. When the
call is executed, the PC is loaded with the specified program-memory address
and program execution begins at that address. The address loaded into the
PC may come from either the second word of the call instruction or the lower
sixteen bits of the accumulator. Before the PC is loaded, the return address
is saved in the stack. After the subroutine or function is executed, a return
instruction loads the PC with the return address from the stack, and execution
resumes at the instruction following the call.