In computer programming, control flow refers to the order in which statements in a program are executed. Control flow determines the sequence in which the instructions in a program are executed based on certain conditions, such as the values of variables or the results of comparisons.

What is branch statement

In computer programming, a branch statement is a statement that alters the normal control flow of a program by directing the execution to a different part of the program. Branch statements are often used in conjunction with conditional statements to create different execution paths based on conditions.

There are several types of branch statements in programming, including:

  1. Unconditional branch statements: These statements always transfer control to the specified target location, without any condition check. Examples include the goto statement in C/C++ and the jmp statement in assembly language.
  2. Conditional branch statements: These statements transfer control to the specified target location only if a certain condition is true. Examples include the if and else statements in C/C++ and the branch-if statement in assembly language.
  3. Switch statements: These statements transfer control to one of several possible target locations, based on the value of a given expression. The switch statement in C/C++ and the select statement in Ada are examples of switch statements.

Main control flow statements in Smali:

In Smali, control flow statements are used to modify the flow of execution of the program.

  1. goto statement: This statement transfers control to a different instruction within the same method. It takes a label as an argument, which is the target instruction.
  2. Conditional branch statements: There are several conditional branch statements in Smali that allow you to perform different actions based on the result of a condition. These include:
  3. Switch statement: The switch statement is used to select one of several code blocks to execute based on the value of an expression. Smali supports two types of switch statements:
  4. return statement: This statement is used to terminate the execution of a method and return a value to the calling method.

These control flow statements can be combined to create more complex control flow structures in Smali.

How return works

const/16 v1, 0xa

const/4 v2, 0x5

invoke-virtual {p0, v1, v2}, Llab/seczone64/smalifilestructure/MainActivity;->giveGraterNumber(II)I

move-result v0

Here v0 will store the return value from giveGraterNumber function.

Statement Opcodes

One Register Compare to Zero

Syntax Descryption Example
if-eqz vx, target Equal Zero if vx == 0
if-nez vx, target Not Equal Zero if vx ≠ 0
if-ltz vx, target Less Than Zero if vx < 0
if-gez vx, target Greater Equal Zero if vx ≥ 0
if-gtz vx, target Greater Than Zero if vx > 0
if-lez vx, target Less Equal Zero if vx ≤ 0