diff options
Diffstat (limited to 'src/org/blog/assembly/1.org')
-rw-r--r-- | src/org/blog/assembly/1.org | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/org/blog/assembly/1.org b/src/org/blog/assembly/1.org index 3fd21e4..7a712e3 100644 --- a/src/org/blog/assembly/1.org +++ b/src/org/blog/assembly/1.org @@ -241,3 +241,48 @@ d DB 5 DUP(1, 2) d DB 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 #+END_SRC Of course, you can use DW instead of DB if it's required to keep values larger then 255, or smaller then -128. DW cannot be used to declare strings. +*** LEA +LEA stands for (Load Effective Address) is an instruction used to get the offset of a specific variable. We will see later how its used, but first. here is something we will need : + +In order to tell the compiler about data type, +these prefixes should be used: + +*BYTE PTR* - for byte. +*WORD PTR* - for word (two bytes). + +For example: +*BYTE PTR [BX]* ; byte access. + or +*WORD PTR [BX]* ; word access. +assembler supports shorter prefixes as well: + +b. - for BYTE PTR +w. - for WORD PTR + +in certain cases the assembler can calculate the data type automatically. + +**** Example : +#+BEGIN_SRC asm + org 100h + .data + VAR1 db 50h + VAR2 dw 1234h + .code + MOV AL, VAR1 ; We check the value of VAR1 by putting it in AL + MOV AX, VAR2 ; Same here + LEA BX, VAR1 ; BX receives the Address of VAR1 + MOV b.[BX], 44h + MOV AL, VAR1 ; We effectively changed the content of the VAR1 variable + LEA BX, VAR2 + MOV w.[BX], 5678h + MOV AX, VAR2 +#+END_SRC +*** Constants : +Constants in Assembly only exist until the code is assembled, meaning that if you disassemble your code later, you wont see your constant definitions. + +Defining constants is pretty straight forward : +#+BEGIN_SRC asm + name EQU value +#+END_SRC + +Of course constants cant be changed, and aren't stored in memory. So they are like little macros that live in your code. |