What is the difference between =label (equals sign) and [label] (brackets) in ARMv6 assembly?

后端 未结 2 604
余生分开走
余生分开走 2020-12-05 05:37

I\'m following along with the Baking Pi course from Cambridge University, in which a simple operating system is built in the ARMv6 instruction set, targeting the Raspberry P

2条回答
  •  伪装坚强ぢ
    2020-12-05 06:04

    ldr r0,=something
    ...
    something:
    

    means load the address of the label something into the register r0. The assembler then adds a word somewhere in reach of the ldr instruction and replaces it with a

    ldr r0,[pc,#offset]
    

    instruction

    So this shortcut

    ldr r0,=0x12345678
    

    means load 0x12345678 into r0.

    being mostly fixed length instructions, you cant load a full 32 bit immediate into a register in one instruction, it can take a number of instructions to completely load a register with a 32 bit number. Depends heavily on the number. For example

    ldr r0,=0x00010000
    

    will get replaced by the gnu assembler with a single instruction mov r0,#0x00010000 if it is an ARM instruction, for a thumb instruction though it may still have to be ldr r0,[pc,#offset]

    These ldr rd,=things are a shortcut, pseudo instructions, not real.

    ldr rd,[rm,#offset]
    ldr rd,[rm,rn]
    

    are real instructions and mean read from memory at address rm+offset or rm+rn and take the value read and put it in the register rd

    the =something is more like &something in C.

    unsigned int something;
    unsigned int r0;
    unsigned int r1;
    
    r0 = &something;
    r1 = *(unsigned int *)r0;
    

    and in assembly

    something:
        .word 0
    
    ldr r0,=something
    ldr r1,[r0]
    

提交回复
热议问题