Review:
Control flow
|
The control flow in a subroutine call:
function f1( ) function f2( ) { +------->{ ... | ... | ... | ... | ... call | ... | f2( ) ----------+ ... | ... <--------------+ ... | ... | ... V ... +------ return; } } |
Consider the control flow in the following function call A( ):
main( ) A( ) { +------->{ ... | ... A( ); -----+ ... ... <-------+ ... ... | +-------- ... } } |
Can we implement the control flow using branch instrucions ???
main: A: |
Consider the control flow in the following function call A( ):
main( ) A( ) { +------->{ ... | ... A( ); -----+ ... ... <-------+ ... ... | +-------- ... } } |
Yes, here is the solution:
main: A: ... +-------> ... ... | ... b A ----+ ... Ret: ... <--------+ ... ... | ... +----- b Ret |
Consider another control flow in the following two function calls A( ):
main( ) A( ) { +--------->--+->{ ... | | ... A( ); ------+ | ... ... <------ return 1 | ... ... | ... ... | ... ... | } A( ); -------------------+ ... <------ return 2 ... } |
The function A( ) can only branch to a fixed return location with branch instruction
main: A: ... +-------> ... ... | ... b A ----+ ... Ret: ... <--------+ ... ... | ... ... +----- b Ret ... b A <---- cannot return here with b Ret |
|
|