Adding Numbers Using Pointers
Learn how to add numbers using pointers in GDB disassembly.
Pointers to add numbers
Now, we’ll look at the next pseudocode statement:
[x1] <- [x1] + [x0]
Recall that [x0]
and [x1]
are the contents of memory cells whose addresses (locations) are stored in x0
and x1
CPU registers.
We look at how we add numbers by using pointers in the following languages:
In the C/C++ language
The expression [x1] <- [x1] + [x0]
is equivalent to the following C/C++ language expression:
*pb = *pb + *pa;
In this expression, the *
operator is an instruction to retrieve memory contents pointed to by the pointers pa
or pb
(also called pointer dereference).
In the assembly language
In the assembly language, we use the instruction add
for the +
operator, but we cannot use memory addresses in one-step instruction:
add [x1], [x0] // invalid instruction
We can only use registers, and therefore, we need to employ two registers as temporary variables, as shown in the assembly pseudocode below:
Get hands-on with 1400+ tech skills courses.