In the previous article, I explained the basic architecture of the registers of the ARM64 processor, and explained how they can be used by an assembly

Code in ARM Assembly: Working with pointers

submited by
Style Pass
2021-06-21 07:30:08

In the previous article, I explained the basic architecture of the registers of the ARM64 processor, and explained how they can be used by an assembly language routine to access and return values. I ended with a cliffhanger, promising to explain how arguments can be accessed from pointers passed to a routine.

There are two basic instructions for transferring data between memory and registers, LDR which loads into a register, and STR which stores into memory. Their simplest use is:

Note how the direction of movement differs in the two: LDR loads the first operand as the destination, whereas STR stores what’s in the first operand as the source. Instructions more commonly use the first operand to specify the destination of the result; STR is an important exception.

The reg item in those instructions can use any of five different addressing modes: [X1] – base register, which can include SP to use the stack pointer [X1,offset] – base register with an offset, in which the effective address is the sum of the address in the base register and the offset [X1,offset]! – pre-indexed, which works like an offset, but before use the address in the register has the offset added to it; this is commonly used for loading or storing values in an array [X1],offset – post-indexed, which works like an offset, but as a result of this instruction the address in the register is updated by adding the offset at the end of execution; this is commonly used for popping values from the stack label – PC relative, which is used for accessing values defined in the code by a label.

Leave a Comment