Command pointer
Bytes --------------------------------------------------------------------------------------------
Unconditional Branch:
Jump
Call
Interrupted
-----------------------
1. Jump command
JMP = GOTO
Short jump
Near jump
Remote jump
2. Call commands
Call # Save the EIP value to the stack
RET # restore the original EIP value to the EIP register
3. Interrupt command
Int
Iret
Soft Interrupt 0x80
Hard interrupt
Bytes --------------------------------------------------------------------------------------------
Condition Branch:
Conditional jump command
Jxx address
Short jump
Near jump
----------------------
1. Use comparison commands
CMP operand1, operand2 # operand2-operand1
2. Use a flag
Use zero flag
Use overflow flag
Use parity flag
Use symbol flag
Use carry flag
Command for modifying carry flag
CLC # clear --> 0
CMC # Reverse Lookup
STC # settings --> 1
-----------------------
Bytes --------------------------------------------------------------------------------------------
Loop
Loop # loop until ECx = 0
Loope/loopz # loop until ECx = 0, or ZF = 0
Loopne/loopnz # loop until ECx = 0, or ZF = 1
Only short jump is allowed (that is, the 8-bit offset)
Count with ECx
When executing the loop command, first reduce ECx by 1 and then judge whether it is 0
Jcxz checks whether ECx is 0
Bytes --------------------------------------------------------------------------------------------
Salx # Left shift command
Leax # address transfer command
Bytes --------------------------------------------------------------------------------------------
Branch prediction:
The processor takes precedence over backward branches (that is, executing executed commands ),
If there is no backward branch, the command next to the jump command is preferred (that is, the command after the non-jump destination)
(For C-language if-else statements, the command next to if is preferred, instead of the command after else)
Branch Target Buffer: tracks each branch instruction executed by the processor, and then uses this data to predict the branch
Bytes --------------------------------------------------------------------------------------------
Optimization tips:
1. Remove Branch
Use cmov to replace the jump command
2. write code in the predictable branch first.
For example, the code in the loop is next to the code of the jump command.
3. Expand the loop