Lecture 5 - Defining Data and Symbolic Constants
Lecture 5 - Defining Data and Symbolic Constants
1
Intrinsic Data Types (1 of 2)
• BYTE, SBYTE
• 8-bit unsigned integer; 8-bit signed integer
• WORD, SWORD
• 16-bit unsigned & signed integer
• DWORD, SDWORD
• 32-bit unsigned & signed integer
• QWORD
• 64-bit integer
• TBYTE
• 80-bit integer
2
Intrinsic Data Types (2 of 2)
• REAL4
• 4-byte IEEE short real
• REAL8
• 8-byte IEEE long real
• REAL10
• 10-byte IEEE extended real
3
Data Definition Statement
value1 BYTE 10
4
Defining BYTE and SBYTE Data
Each of the following defines a single byte of storage:
5
Defining Byte Arrays
6
Defining Strings (1 of
3)
• A string is implemented as an array of characters
• For convenience, it is usually enclosed in quotation
marks
• It often will be null-terminated
• Examples:
7
Defining Strings (2 of
3)
• To continue a single string across multiple lines, end
each line with a comma:
8
Defining Strings (3 of
3)
• End-of-line character sequence:
• 0Dh = carriage return
• 0Ah = line feed
9
Using the DUP Operator
• Use DUP to allocate (create space for) an array or
string. Syntax: counter DUP ( argument )
• Counter and argument must be constants or constant
expressions
BYTE 20 DUP(0) ;20 bytes,all equal to zero o
10
Defining WORD and SWORD Data
11
Defining DWORD and SDWORD Data
12
Defining QWORD, TBYTE, Real Data
13
Little Endian Order
• Example:
val1 DWORD 12345678h
14
Adding Variables to AddSub
TITLE Add and Subtract, Version 2 (AddSub2.asm)
; This program adds and subtracts 32-bit unsigned
; integers and stores the sum in a variable.
INCLUDE Irvine32.inc
.data
val1 DWORD 10000h
val2 DWORD 40000h
val3 DWORD 20000h
finalVal DWORD ?
.code
main PROC
mov eax,val1 ; start with 10000h
add eax,val2 ; add 40000h
sub eax,val3 ; subtract 20000h
mov finalVal,eax ; store the result (30000h)
call DumpRegs ; display the registers
exit
main ENDP
END main
15
Declaring Unitialized Data
16
Equal-Sign Directive
• name = expression
• expression is a 32-bit integer (expression or constant)
• may be redefined
• name is called a symbolic constant
• good programming style to use symbols
COUNT = 500
.
.
mov al,COUNT
17
Calculating the Size of a Byte Array
18
Calculating the Size of a Word Array
19
Calculating the Size of a Doubleword Array
20
Real-Address Mode Programming (1 of 2)
21
Real-Address Mode Programming (2 of 2)
• Requirements
• INCLUDE Irvine16.inc
• Initialize DS to the data segment:
mov ax,@data
mov ds,ax
22
Add and Subtract, 16-Bit Version
TITLE Add and Subtract, Version 2 (AddSub2r.asm)
INCLUDE Irvine16.inc
.data
val1 DWORD 10000h
val2 DWORD 40000h
val3 DWORD 20000h
finalVal DWORD ?
.code
main PROC
mov ax,@data ; initialize DS
mov ds,ax
mov eax,val1 ; get first value
add eax,val2 ; add second value
sub eax,val3 ; subtract third value
mov finalVal,eax ; store the result
call DumpRegs ; display registers
exit
main ENDP
END main
23