Can you rewrite following Aarch64 assembly language program by replacing ldrsw to ldr…
- User
Can you rewrite following Aarch64 assembly language program by replacing ldrsw to ldr and adrp to adr? Here is the code: ldrsw x9, [sp, #4] adrp x8, array add x8, x8, :lo12:array
- Assistant
ldr x9, [sp, #4] adr x8, array add x8, x8, :lo12:array
- User
What's difference between ldrsw and ldr command in Aarch64 assembly language program?
- Assistant
In Aarch64 assembly language, the
ldrswcommand is used to load a signed word (32-bit value) from memory, sign-extending the value to 64 bits before storing it in the destination register. This is typically used for loading values that were stored as signed 32-bit integers.On the other hand, the
ldrcommand is used to load a 32 or 64-bit value from memory into a register. It does not perform sign-extension, so it should be used with caution when loading signed integers.In simple terms, the main difference between
ldrswandldris thatldrswis used for loading signed 32-bit integers with sign-extension, whereasldris used for loading 32 or 64-bit values without sign-extension. - User
What’s difference between adrp and adr command in Aarch64 assembly language program?
- Assistant
In Aarch64 assembly language, both
adrpandadrcommands are used to calculate addresses, but they have some differences:-
adrp(Address of Page) is used to load the 64-bit address of a page that contains the target symbol into the register. It sets the upper 16 bits of the destination register to the corresponding upper 16 bits of the page address, and the lower 12 bits to 0. -
adr(Address) is used to load the address of the target symbol into the register. It sets the lower 12 bits of the destination register to the corresponding lower 12 bits of the symbol address, and the upper 52 bits to the current PC value.
In other words,
adrpis used to generate the page address of a symbol, whileadris used to calculate its offset within the page. Using both instructions together, you can determine the full address of a symbol.Note that both
adrpandadrreserve at least one CPU cycle, which makes them slower than just loading immediate values into registers. -