1 / 12

New/Old Assembler Directives

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)

nani
Download Presentation

New/Old Assembler Directives

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. New/Old Assembler Directives

  2. 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.

  3. 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

  4. 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

  5. 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

  6. 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”

  7. 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.

  8. 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.

  9. 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)

  10. 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

  11. 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”

More Related