...
/Assigning Numbers to Memory Using Pointers
Assigning Numbers to Memory Using Pointers
Learn how to assign numbers to memory locations using pointers.
We'll cover the following...
We'll cover the following...
Pointers to assign numbers
The following sequence of pseudocode instructions means that we interpret the contents of the x0 register as the address of a memory cell and then assign a value to that memory cell:
In the C/C++ language
In C and C++, it is called dereferencing a pointer:
In the assembly language
In the assembly language, we write the following:
In GDB disassembly output
In the GDB disassembly output, we see something like this:
Explanation
To illustrate some instructions and not to be dependent on how the compiler translates C/C++ code, we wrote the program in the assembly language.
Source code
The source code of the pointers is given below:
Here is a breakdown of the code presented above:
- Lines 1–11: These are the header commands of the assembly code.
- Line 12: We load the address of
aand store it inx0register. - Line 13: We assign
#1to the registerw3. - Line 14: Then, we store the value from register
w3and assign it to the address pointed byx0. - Line 16: We load the address of
band store it inx1register. - Line 17: We store the value from register
w3and assign it to the address inx1. - Line 19: We load the value in
[x0]and store it in thew2register. - Line 20: We load the value in
[x1]and store it in thew3register. - Line 21