The difference between the assembly jump instruction B, BL, BX, BLX and BXJ

Source: Internet
Author: User
Tags mongodb postgresql redis relative
The jump instruction is used to realize the jump of the program flow. There are two ways to realize the jump of the program flow in the ARM program:

(1) Use special jump instructions.

(2) Write the jump address value directly to the program counter PC.

By writing the jump address value to the program counter PC, any jump in the 4GB address space can be realized, which can be used in combination before the jump

MOV LR, PC

For similar instructions, you can save the next instruction address as the future return address value, so as to realize the subroutine call in the 4GB continuous linear address space. Dedicated jump instruction

B, BL, BX, BLX and BXJ:

Jump, jump with link (jump with return), jump and switch instruction set, jump with link and switch instruction set (jump with return and switch instruction set), jump and switch to Jazelle state.

1. B command

The format of the B command is:

B{condition} destination address

The B instruction is the simplest jump instruction. Once a B instruction is encountered, the ARM processor will immediately jump to the given target address and continue from there.
Continued execution. Note that the actual value stored in the jump instruction is an offset from the current PC value, not an absolute address, and its value is calculated by the assembler (refer to relative addressing in addressing mode). It is a 24-bit signed number, which is signed to 32 bits after shifting to the left by two bits. The effective offset is 26 bits (32MB before and after the address space). The following instructions:

B Label; the program jumps to the label Label unconditionally for execution

CMP R1, # 0; when the Z condition code in the CPSR register is set, the program jumps to the label Label for execution

BEQ Label 2, BL instruction

The format of the BL instruction is:

BL{condition} target address

BL is another jump instruction, but before the jump, the current content of the PC will be saved in the register R14. Therefore, the content of R14 can be reloaded into the PC to return to the instruction after the jump instruction. . This instruction is a basic but commonly used means to implement subroutine calls. The following instructions:

BL Label; when the program unconditionally jumps to the label Label for execution, the current PC value will be saved to R14 at the same time. 3. BLX instruction

The format of the BLX instruction is:

BLX destination address

The BLX instruction jumps from the ARM instruction set to the target address specified in the instruction, and switches the working state of the processor from the ARM state to the Thumb state. The instruction also saves the current content of the PC to the register R14. Therefore, when the subroutine uses the Thumb instruction set and the caller uses the ARM instruction set, the BLX instruction can be used to implement the call of the subroutine and the switch of the processor working state.

At the same time, the return of the subroutine can be completed by copying the value of register R14 to the PC.

4. BX instruction The format of BX instruction is:

BX{condition} target address

The BX instruction jumps to the target address specified in the instruction. The instruction at the target address can be either an ARM instruction or a Thumb instruction. to sum up
grammar

op1{cond}{.W} <wbr />label
 
op2{cond} <wbr />Rm

among them:

op1

Is one of the following:

B

Jump.

BL

Jump with link

BLX

Jump with link and switch instruction set.

op2

Is one of the following:

BX

Jump and switch instruction set.

BLX

Jump with link and switch instruction set.

BXJ

Jump and switch to Jazelle execution.

cond

Is an optional condition code. cond cannot be used in all forms of this instruction.

.W

Is an optional instruction width specifier used to force the use of 32-bit B instructions in Thumb-2.

label

Is a program-relative expression.

Rm

It is a register that contains the target address to jump to.

operating

All these instructions will cause a jump, or jump to label, or jump to the address contained in Rm. In addition:

The BL and BLX instructions can copy the address of the next instruction to lr (r14, link register).

The BX and BLX instructions can change the state of the processor from ARM to Thumb, or from Thumb to ARM.

BLX label always changes the state of the processor in any case.

BX Rm and BLX Rm can calculate the target state from bit [0] of Rm:

If bit [0] of Rm is 0, the state of the processor will change to (or remain in) the ARM state

If bit [0] of Rm is 1, the state of the processor will change to (or remain in) the Thumb state.

The BXJ instruction will change the state of the processor to Jazelle
http://www.techbulo.com/535.html

http://luleimi.blog.163.com/blog/static/175219645201210922139272/

Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

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.