At&t ASM learning 5

Source: Internet
Author: User

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

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.