qa.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
data.asm
   Example  Back  Contents  Index
──────────────────────────────────────────────────────────────────────────────
 
;* DATA.ASM illustrates how to declare variables with data-definition
;* directives.
;*
;* Shows:   Directives - DB     DW     DD     DQ     DT     LABEL
;*          Operator - DUP
 
        .MODEL small
        .STACK
        .DATA
; Integers
bvar    DB      16                      ; Byte initialized as 16
wvar    DW      4 * 3                   ; Word initialized as 12
dvar    DD      4294967295              ; Double word as 4,294,967,295
qvar    DQ      ?                       ; Quad word (8-byte) uninitialized
        DB      1, 2, 3, 4, 5           ; Five initialized bytes
ten     DT      2345                    ; 10-byte integer as 2,345
fp      DD      6.3153                  ; 8-byte real number
 
; Strings and characters
abc     DB      'a', 'b', 'c'           ; Three characters (same as 'abc')
hello   DB      'Hello', 13, 10, '$'    ; String for DOS Function 9h
msg     DB      13, 10, "Another hello" ; String for DOS Function 40h
len     EQU     $ - msg                 ; Length in bytes of msg
dir     DB      "CCPROGS", 0          ; String data for C
npdir   DW      BYTE PTR dir            ; Near pointer to char (C string)
fpdir   DD      BYTE PTR dir            ; Far pointer to char (C string)
 
; Arrays and buffers
dbuf    DW      25 DUP (?)              ; 25 uninitialized doublewords
bbuf    DB      12 DUP ('month')        ; 60-byte array, each 5-byte
                                        ;   group initialized to 'month'
fpdbuf  DD      WORD PTR dbuf           ; C array is pointer to array data
two_d   DW      5 DUP (5 DUP (0))       ; Allocate 25 words initialized to 0
warr    LABEL   WORD                    ; Access next array as 50 words
darr    LABEL   DWORD                   ; Access same array as 25 doublewords
barr    DB      100 DUP (0, 16, 33, 48) ; Access array as 100 bytes, each
                                        ;   group initialize to bit mask
        .CODE
        .STARTUP
; Fragment examples of loading integer data
        mov     bl, bvar                ; Load byte variable to AL
        mov     ax, WORD PTR dvar[0]    ; Load double to DX:AX
        mov     dx, WORD PTR dvar[20]
        IFDEF   coprocessor             ; Define symbol to test this line
        fld     fp                      ; Load real variable into ST(0)
        ENDIF
 
; Fragment examples of loading string
        mov     dx, OFFSET hello        ; Load and write $-terminated string
        mov     ah, 9                   ; Display String
        int     21h
        mov     dx, OFFSET msg          ; Load and write string with length
        mov     cx, len                 ; Length of msg
        mov     bx, 1                   ; File handle one (the console)
        mov     ah, 40h                 ; Write File or Device
        int     21h                     ;
        lds     dx, fpdir               ; Load far pointer to ASCIIZ to DS:DX
        mov     ah, 3Bh                 ; Set Current Directory
        int     21h
 
        .EXIT                           ; Terminate Program
 
        END
                                    -♦-