Assigning Numbers to Memory Cells Using Pointers
Learn how to assign numbers to memory locations using pointers.
Pointers to assign numbers
The following sequence of pseudocode is a set of instructions to interpret the contents of the %RAX
register as the address of a memory cell and then assign a value to that memory cell:
address a -> rax
1 -> (rax)
Assigning numbers in C and C++
In C and C++, assigning a number is called dereferencing a pointer, and we write:
int a;int *pa = &a; // declaration and definition of a pointer*pa = 1; // get a memory cell (dereference a pointer) and assign a value to it
Assigning numbers in assembly language
In assembly language, we write:
lea a, %rax # load the address “a” into %raxmovl $1, (%rax) # use %rax as a pointer
The lea
(load effective address) instruction is a method of obtaining an address from one of the Intel processors’ memory addressing modes. It moves the contents of the specified memory address to the destination register. Again, we see movl
instead of mov
because integers occupy -bit memory cells, and we want to address only a ...
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy