3.6 control (control)
jump
The instructions may change the order of execution of a set of machine code instructions.
3.6.1 Condition Code (condition code)
Condition code register.
CF2 (In Flag with Carry) : Carry flag . Recent operating the highest position a carry. It is used to check unsigned overflow operation.
ZF (ZERO Flag) : Zero flag . Recently the results of the operation is zero.
SF (Signed In Flag) : a sign flag . Recent results obtained in the negative.
OF (overflow Flag) : overflow flag . Recent operating results in a complement overflow - positive or negative overflow overflow.
Sign flag ( ) |
carried out | effect |
---|---|---|
CF |
(unsigned) t < (unsigned) a |
Unsigned overflow |
ZF |
t == 0 |
zero |
SF |
t < 0 |
negative number |
OF |
a < 0 == b < 0 && (t < 0 != a<0 |
Signed overflow |
leaq
Instruction code does not change any condition, because it is used for address calculations.
3.6.2 Access condition code
Condition code is not normally read directly, using a method commonly used in three ways:
1) some combination according to the condition code, one byte is set to 0 or 1;
2) is a conditional jump to another program portion;
3) can be conditionally transmitted data.
3.6.3 jump instruction
3.6.4 jump instruction encoding
3.6.5 controlled conditions to achieve with Conditions
The conditional expressions and statements translated from the C language into machine code, the most common way to combine conditional and unconditional jumps.
The general form of C language template if-else statement is as follows:
if (test-expr)
then-statement
else
else-statement
The corresponding assembly is typically used to achieve this the following form. In C language syntax to describe the flow of control:
t = test-expr;
if (!t)
goto false;
then-statement;
goto done;
false:
else-statement;
done:
3.6.6 implemented by a conditional branch conditional transfer
The conventional method is achieved by using the operation condition of the control to be redirected (condition is detected, A; otherwise, execution B).
An alternative strategy is to use the data in the transfer conditions (under certain conditions, the conditions previously listed results, according to the data results directly select the next path condition is performed).
Example ( ret
returned parameters stored in %rax
the):
penalties branch misprediction of
conditional transfer instructions
if a conditional branch any side effects or possible error condition will result in an illegal act.
3.6.7 cycle
1. do-while loop
2. while loop
The first translation method jump to middle
( )
Example:
The second translation method guarded-do
( )
Example:
interesting features. Cycle test (the first assembly code 9
lines) from the original C
code n>1
becomes n != 1
. When the compiler knows only n > 1
when entering the loop, it will n
reduce 1
mean n > 1
or n = 1
. Therefore, the test n != 1
is equivalent to testing n >= 1
. (I have not verified)
3. for loop
The general format of the for loop:
for (init-expr; test-expr; update-expr)
body-statement
Equivalent to:
init-expr:
while(test-expr){
body-statement
update-expr;
}
Jump to the middle of the strategy goto Code:
init-expr;
goto test;
loop:
body-statement;
update-expr;
test:
t = test-expt;
if(t)
goto loop;
The guarded-do policies get:
init-expr;
t = test-expr;
if(!t)
goto done;
loop:
body-statement;
t = test-expt;
if(t)
goto loop;
done:
In summary, all three forms of C language cycle of - , do-while
, while
and for
can be used to translate a simple strategy, generates the code comprising one or more conditional branch. Controlled conditions to provide a basic transfer mechanism for circulating translated into machine code.
3.6.8 switch statement
switch
(Switch) statements can be multiple branches (in accordance with an integer index multiway branching
).
The jump table is an array entry i
is the address of a code segment, the code segments is equal to the index value when the switching i
operation of the program should be taken.
Example:
Jump table