当前位置:网站首页>Arm immediate

Arm immediate

2022-06-25 12:12:00 xiaozhiwise

/*
 * 2018/12/20    11:43    qing
 */

/*
 * ARM Medium MOV Command format
 */

    31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
    |   Cond   | 0 0 | L| OpCode    | S |   Rn     |  Rd       |       Operand2                   |


    op2 Yes, it accounts for 12 position , among bit 11 - bit 8 Is shift (rotate), bit 7 - 0 It's a 8 The immediate number of bits (imm),
    
    mov    Rn, op2        @ After performing Rn = op2 >> (rotate * 2), The shift here is a cyclic right shift , It's up to mov Not all immediate numbers can be represented by an instruction


    1. mov r3, #0x56000000

         although 0x56000000 It's a 32 The number of bits , But you can find such a 8 Immediately , Move right to get , Look at the machine code e3a03456 , Expand to binary , Compare the format below

        31       27    23     19     15     11     7      3
        1110  0011  1010  0000  0011  0100  0101  0110

        Cond[31:28] = 1110

        [27:26] = 00

        L[25] = 1 , representative op2 It's an immediate number

        OpCode[24:21] = 1101

        S[20] = 0

        Rn[19:16]= 0000

        Rd[15:12]= 0011 , R3

        Op2[11:8]= 0100 , Move right 4 * 2 position

        Op2[7:0] = 0101 0110 , 8 Immediately , 0x56        

         First of all to 0x56 Expanded into 32 Signed number of bits , 0x00000056 , Then cycle right 8 position , Got it. 0x56000000


    2. mov r3, #0x56000014

        0x56000014 You can't get it by shifting , The compiler will report an error ,C A program written in a language , The compiler does this :

        mov r3, #0x56000000

        add r3, r3, #0x14        

         Instead of mov Another instruction of is ldr, It might be more convenient .

    

/*
 * stay ARM The rule of using immediate numbers in
 */

     stay ARM It can't be like X86 That way, the immediate number is directly loaded into the register . Because the immediate number you use is limited .

     Can pass LDR Bypass these restrictions , There are the following techniques :


     Every one of them ARM The width of the instruction is 32 position , All instructions are conditionally executable .
    
     Yes 16 Medium conditions can be used, and the occupation of each condition in the machine code is 4 position . After that we need 2 Bit as destination register .2 Bit as the first operation register ,
    
    1 Bit is used as the flag bit for setting the status , Plus, for example, opcodes (opcode) Occupation of these . Finally, each instruction leaves us only space for storing immediate numbers 12 A wide . That is to say 4096 Different values .


     That means ARM In the use of MOV The immediate range of values that can be manipulated when instructing is limited . If it's big , It can only be split into multiple parts and spliced with a shift operation .

     So the rest 12 Bits can be divided again ,8 Bit is used for loading 0-255 Any value in ,4 Bit is used to do 0~30 Cyclic right shift of bits .
    
     This means that the immediate number can be obtained by this formula :v = n ror 2 * r. let me put it another way , Valid immediate values can be obtained by moving right in a loop .
    
    
     Here's an example

     Valid values :

    #256        // 1 Cycle moves to the right 24 position --> 256
    #384        // 6 Cycle moves to the right 26 position --> 384
    #484        // 121 Cycle moves to the right 30 position --> 484
    #16384      // 1 Cycle moves to the right 18 position --> 16384
    #2030043136 // 121 Cycle moves to the right 8 position --> 2030043136
    #0x06000000 // 6 Cycle moves to the right 8 position --> 100663296 ( Hexadecimal value 0x06000000)

    Invalid values:

    #370        // 185 Cycle moves to the right 31 position --> 31 Out of range (0 – 30)
    #511        // 1 1111 1111 --> The bit model does not conform to
    #0x06010000 // 1 1000 0001.. --> The bit model does not conform to

原网站

版权声明
本文为[xiaozhiwise]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251202417244.html

随机推荐