Defining Data

advertisement
Intrinisic Data Types
TYPE
BYTE
SBYTE
WORD
SWORD
DWORD
SDWORD
FWORD
QWORD
TBYTE
REAL4
REAL8
REAL10
Usage
8-bit unsigned integer
8-bit signed integer
16-bit unsigned integer (can also be a Near pointer in Real-address mode)
16-bit signed integer
32-bit unsigned integer (can also be a Near pointer in Protected mode)
32-bit signed integer
48-bit integer (Far pointer in Protected mode)
64-bit integer
80-bit (10 byte) integer
32-bit (4 byte) IEEE short real
64-bit (8 Byte) IEEE long real
80-bit (10 byte) IEEE extended real
New/Old Assembler Directives
New
Directives
Old
Directives
BYTE
DB
W ORD
DW
DW ORD
DD
QW ORD
DQ
TBYTE
DT
Data Definition Statement
• syntax
– [name] directive initializer [,initializer]…
• At least one initializer is required in a data definition
even if it is ? (does not assign a specific value)
– The name is a label that marks the offset of a
variable from the beginning of its enclosing
segment.
Examples
•
•
•
•
•
Var1
Var2
Var3
Var4
Var5
BYTE
byte
db
sbyte
byte
35h
255
‘A’
-128
?
;use h for hex
;case not checked
;old syntax
;signed byte
;uninitialized
Defining Lists
•
•
•
•
.data
List
List2
List3
byte
byte
byte
byte
byte
10, 20, 30, 40
10, 32, 41h, 00100010b
10, 20, 30, 40
50, 60, 70, 80
90, 100, 120
Defining Strings
• String1
• String2
• String3
• String4
byte
byte
byte
byte
byte
\
byte
byte
byte
“This is a string”, 0
‘T’,’h’,’i’,’s’,‘i’,….
“This is a long string that”
“that extends across many”
“lines”, 0Dh, 0Ah,0
“Continuation character \ may be”
“ used to concatenate two lines”
“ into one.”,0
Using the DUP Operator
• Generates a repeated storage allocation, using a
constant expression as a counter
• BYTE
20
DUP(0)
– Results in 20 bytes, all equal to 0
• BYTE
20
DUP(?)
– Results in 20 bytes, uninitialized
• BYTE
4
DUP(“STACK”)
– Results in 20 bytes “STACKSTACKSTACKSTACK”
Symbolic Constants
• Created by associating an identifier with
either an integer value or some text. Does
not reserve any storage. They are only used
during assembly of a program, so they
cannot change value during runtime.
Equal-Sign Directive
• Associates a symbol name with an integer value
• .code
– COUNT = 500
– Mov
al, COUNT
• .code
– ESC_KEY = 27
– Mov
al, ESC_KEY
• .data
– COUNT = 50
– Array COUNT DUP(0)
• Useful for constants. Easy to later change one line
of code.
Calculating the Sizes of Strings
and Arrays
• Use the current location counter ($).
– List byte 10, 20,30, 40
– ListSize = ($ - list)
• The calculation must be done immediately
following the list definiton
– mystring byte “This is my string”,0
– String_len = ($ - mystring –1)
Calculating the Sizes of Strings
and Arrays of Words and
Doublewords
• List
WORD
1000h, 2000h, 3000h
• Listsize = ($ - list) / 2
• List
DWORD 10000000h,20000000h,
DWORD 30000000h,40000000h
• Listsize = ($ - list) / 4
• This is important when using loops through arrays
Lists and Strings
List1 db 10, ‘A’, 41h, 0Ah, 00100010b, 101q
Listptr db List1
Cstring db “This is a string”,0
Clength = ($ - Cstring)
; sets Clength to length of Cstring
Array1 db 20 dup(0)
; 20 bytes, all equal to zero
Array2 db 4 dup(“ABC”) ; 12 bytes, “ABCABCABCABC”
Download