A data segment contains static data described by a sequence of data defining assembler pseudo-ops. These pseudo-ops provide information such as:
The general form for the above pseudo-ops is:
[<name>] pseudoop <constant-list> [<comment>] where
<name> - is the symbolic name associated with the memory location
pseudoop - is one of the MASM defined pseudo-ops
<constant-list> - is a list of constants separated by commas
[<comment>] - is a comment preceded by a semicolon
Note: The brackets signify optional
Let's look specifically at: [<name>] BYTE <byte-constant-list>
Example: max byte 7
A byte constant is one of the following:
Note2: A minus sign in front of a constant signifies to the assembler to take the two's complement of the binary representation of the number.
P#1: Translate all of the following to HEX:
.data bvalues byte 12,011b,1011b,'A' sbyte 0fah,073q,-12,-0ffh SYMBOLIC NAME BYTE OFFSET HEX CONTENTS ------------- ----------- ------------
The WORD pseudo-op works similarly to the BYTE except that remember a word is stored in memory with bytes reversed (low byte, high byte).
P#2: Translate all of the following to HEX:
.data wvalues SWORD ?,-377Q,012ABH minus1 SWORD -1 SYMBOLIC NAME BYTE OFFSET HEX CONTENTS ------------- ----------- ------------
The duplicate clause can be used for a constant list that contains repetition. The general form is:
<repeat-count> DUP (<constant-list>)
where the <constant-list> is to be duplicated <repeat-count> times in succession. Duplicate clauses can be nested.
As examples, 6 DUP(0) implies 0,0,0,0,0,0 and 3 DUP(3 DUP(0),1) implies 0,0,0,1,0,0,0,1,0,0,0,1
P#3: Translate the following to HEX:
.data prompt sbyte 'A' n sword ? arry sword 5 dup(0,1) flag sbyte -2 ans sword -17q data ends SYMBOLIC NAME BYTE OFFSET HEX CONTENTS ------------- ----------- ------------
The final topic of discussion revolves around constants. There are two kinds of constant definitions: (1) EQU and (2) .CONST.
EQU - this pseudo-op assigns a symbolic name to a constant value. This symbolic name can then be used within the assembly language program. This symbolic name is more meaningful and just a constant value and thus improves the readability of the program.
Example: false equ 0 true equ 1
A symbolic constant is only known during the assembly process, i.e. the assembler changes all occurrences of the symbol to the actual value during translation.