130 likes | 250 Views
New/Old Assembler Directives. 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)
E N D
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 BYTE 35h ;use h for hex • Var2 byte 255 ;case not checked • Var3 db ‘A’ ;old syntax • Var4 sbyte -128 ;signed byte • Var5 byte ? ;uninitialized
Defining Lists • .data • List byte 10, 20, 30, 40 • List2 byte 10, 32, 41h, 00100010b • List3 byte 10, 20, 30, 40 byte 50, 60, 70, 80 byte 90, 100, 120
Defining Strings • String1 byte “This is a string”, 0 • String2 byte ‘T’,’h’,’i’,’s’,‘i’,…. • String3 byte “This is a long string that” byte “that extends across many” byte “lines”, 0Dh, 0Ah,0 • String4 \ byte “Continuation character \ may be” byte “ used to concatenate two lines” byte “ 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”