Pointers and references: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) |
||
Line 47: | Line 47: | ||
A pointer can be loaded into a register like any other value. |
A pointer can be loaded into a register like any other value. |
||
<lang asm> |
<lang asm>.data |
||
.data |
|||
myString db "Hello World!",0 ;the zero is the null terminator |
myString db "Hello World!",0 ;the zero is the null terminator |
||
.code |
.code |
||
Line 56: | Line 55: | ||
Once we have the pointer to myString in bx, we can perform arithmetic on it like it was an ordinary numerical value. There is no distinction between pointer arithmetic and normal arithmetic in assembly. All arithmetic commands are available for use. If the programmer wishes to use that memory address as a number for some other purpose, that is perfectly legal. However this example will stick to the "proper" uses of pointer arithmetic, i.e. indexing and offsetting. |
Once we have the pointer to myString in bx, we can perform arithmetic on it like it was an ordinary numerical value. There is no distinction between pointer arithmetic and normal arithmetic in assembly. All arithmetic commands are available for use. If the programmer wishes to use that memory address as a number for some other purpose, that is perfectly legal. However this example will stick to the "proper" uses of pointer arithmetic, i.e. indexing and offsetting. |
||
<lang asm> |
<lang asm>add bx, 2 ;add 2 to bx. bx contains the memory address of the first "l" in "Hello" |
||
mov al,[ds:bx] ;dereference the pointer and store the value it points to into al.</lang> |
mov al,[ds:bx] ;dereference the pointer and store the value it points to into al.</lang> |
||