Pointers and references: Difference between revisions

m
Line 47:
 
A pointer can be loaded into a register like any other value.
<lang asm>.data
.data
myString db "Hello World!",0 ;the zero is the null terminator
.code
Line 56 ⟶ 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.
<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>
 
1,489

edits