Arm Instruction Set> jump command

Source: Internet
Author: User

1. Jump command

The jump command is used to redirect a program flow. There are two methods in the arm program to redirect a program flow:

I. use special jump commands.

Ii. Write the jump address value directly to the program counter PC.

By writing jump address values to the program counter PC, you can achieve any jump in the 4 GB address space. Before the jump, you can use similar commands such as mov LR and PC, future return address values can be saved to implement subroutine calls in a 4 GB continuous linear address space.

The jump command in the arm instruction set can jump 32 MB forward or backward from the current instruction set, including the following four commands:

 

1. Instruction B

The format of instruction B is:

B {condition} target address

B command is the simplest jump command. Once a B command is run, the ARM processor immediately jumps to the specified target address and continues execution from there. Note that the actual value stored in the jump command is an offset relative to the current Pc value, rather than an absolute address. The value is calculated by the assembler (refer to the relative addressing in addressing mode ). It is a 24-bit signed number. After the two digits left are moved, the signed number is extended to 32 bits, indicating that the valid offset is 26 bits (the 32 MB address space before and after ). Run the following commands:

B label; the program jumps to the label unconditionally and executes the label.

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

Beq label

 

2. Bl commands

The BL Instruction format is:

BL {condition} target address

BL is another jump command, but before the jump, the current content of the PC is saved in register R14. Therefore, you can reload the content of R14 to the PC, to return the execution of the command after the jump command. This command is a basic but common method for implementing subroutine calls. Run the following commands:

BL label. When the program jumps to the label unconditionally, it saves the current Pc value to R14.

 

3. blx commands

The blx command format is:

Blx target address

The blx command redirects from the arm instruction set to the target address specified in the instruction set, and switches the processor to the thumb state in the active state. The command 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 set can be used to call the subroutine and switch the working state of the processor. At the same time, the return of the subroutine can be completed by copying the R14 value of the Register to the PC.

 

4. bx commands

The format of the Bx command is:

BX {condition} target address

The BX command jumps to the target address specified in the command. The command at the target address can be either an arm command or a thumb command.

 

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.