B Jump instruction: It is a relative jump instruction, its machine code format is as follows:
[31:28] bit is the condition code ; [27:24] bit is "1010" ( 0xeaffffff ) when , indicating B Jump Instructions , for "1011" , it means BL Jump instruction; [23:0] represents an offset address.
when jumping with B or bl, the address of the next instruction is calculated as follows:
expands the 24-bit signed complement immediate number in the instruction to 32 (expands its sign bit ), shifts the 32-digit number to the left two bits, and adds the resulting value to the PC register, which is the destination address of the jump.
Routines:
1.text
2.global _start
3_start:
4 B Step1
5 Step1:
6 Ldr pc, =STEP2
7 Step2:
8 B Step2
Disassembly code:
0:EAFFFFFF b 0x4
4:e59ff000 Ldr pc, [pc, #0]; 0xc
8:eafffffe b 0x8
c:30000008 Tsteq r0, #8; 0x8
b Jump instruction: It is a relative jump instruction, its machine code format is as follows:
[31:28] bit is the conditional code ; [27:24] bit is "1010" ( 0xeaffffff is a binary of an instruction Machine Code ) when , which means b Jump Instructions , for "1011" , the expression bl Jump instruction; [23:0] The represents a relative to the pc The offset address of the .
expands the complement immediate number of the symbol in the instruction to the ( expand its sign bit ); + shift the number of digits to the left by two bits, and add the resulting value to PC Register, the destination address of the jump is obtained.
Let's take a look at the first instruction "b step1" machine code 0xeaffffff:
1. The 24-bit signed complement is 0XFFFFFF and expands it to 32 to get:0xffffffff
2. This 32-digit left two-bit to get:0XFFFFFFFC, its value is -4 (0XFFFFFFFC sign bit is unchanged, the remaining bits are reversed plus 1 get -4);
3. the value of the PC is the address of the next two ( next bar) instruction of the current instruction, plus the -4 (PC-4, PC fallback ) obtained by step 2 4 bytes, just pointing to the next instruction on the current instruction), which is exactly the address of the second instruction Step1.
Do not be fooled by the "b 0x4" in the disassembly code, it does not mean to jump to the absolute address 0x4 execution, the absolute address is calculated as the above 3 steps.
Learn a summary of the s3c2410 full development process ...
When jumping with B or BL, the address of the next instruction is calculated as