Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ARM64 assembly code, when is register 31 XZR versus SP?

In ARM64 assembly code, when does register number 31 mean XZR and when does it mean SP?

like image 419
Myria Avatar asked Apr 30 '20 21:04

Myria


1 Answers

Whether an instruction interprets register 31 as the zero register wzr/xzr or the stack pointer wsp/xsp depends on the instruction type and isn't easily predictable. The same mnemonic may refer to multiple instructions, some of which accept the stack pointer as an operand and others that don't. In general though, all instructions that make sense to use with the stack pointer have a form where they can be used with the stack pointer. The assembler automatically picks an appropriate form for you. It will never silently take sp to mean xzr or vice versa.

In the ARM Reference Manual, Xn or Wn is used to refer to a register where register 31 refers to the zero register. Xn|SP or Wn|WSP is used to refer to a register where register 31 refers to the stack pointer. See the introduction to §5 “A64 INSTRUCTION SET” for details.

like image 100
fuz Avatar answered Oct 13 '22 20:10

fuz