Professional Documents
Culture Documents
•Defining Data
•Symbolic Constants
3.1 BASIC LANGUAGE ELEMENTS
main PROC
main ENDP
AddTwo program
.data
sum DWORD 0
.code
main PROC
mov eax,5
add eax,6
mov sum,eax
INVOKE ExitProcess,0
main ENDP
Integer Literals
•An integer literal (also known as an integer constant) is made up of an
optional leading sign, one or more digits, and an optional radix
character that indicates the number’s base:
[{+ | - }] digits [ radix ]
•Real Number Literals
[sign] integer.[integer][exponent]
Examples
2., +3.0, -44.2E+05, 26.E5
•Reserved words have special meaning and can only be used in their
correct context (not case sensitive).
• Instruction mnemonics, Register names, Directives
• Attributes, which provide size and usage information for variables and operands.
Examples are BYTE and WORD
• Operators, used in constant expressions
• Predefined symbols, such as @data, which return constant integer values at assembly
time.
•An identifier is a programmer-chosen name. It might identify a
variable, a constant, a procedure, or a code label.
•Rules:
• They may contain between 1 and 247 characters.
• They are not case sensitive.
• The first character must be a letter (A..Z, a..z), underscore (_), @ , ?, or $. Subsequent
characters may also be digits.
• An identifier cannot be the same as an assembler reserved word.
Data label
count DWORD 100
Code label
target of jump and loop instructions
target:
mov ax, bx
…
jmp target
•Instruction Mnemonics:
• .data
• .code
• .stack
• DWORD
DIRECTIVE VS INSTRUCTION
myVar DWORD 26 ;DWORD directive tells the assembler to reserve
space in the program for a doubleword variable.
•Line 16 uses the END directive to mark the last line to be assembled
(end of program), and it identifies the program entry point (main).
• If you add any more lines to a program after the END directive, they will be ignored
by the
assembler.
ASSEMBLING, LINKING, AND RUNNING
PROGRAMS
DEFINING DATA
•The assembler recognizes a basic set of intrinsic data types, which
describe types in terms of their size.
var4 10
0
var4 BYTE 10,3 DUP(0), 20 0
0
20
•Defining WORD and SWORD Data
•The WORD (define word) and SWORD (define signed word)
directives create storage for one or more 16-bit integers:
•All data types larger than a byte store their individual bytes in reverse
order. The least significant byte occurs at the first (lowest) memory
address.
.data
smallArray DWORD 10 DUP(0) ; 40 bytes
bigArray DWORD 5000 DUP(?) ; 20,000 bytes
3.5 SYMBOLIC CONSTANTS
•A symbolic constant (or symbol definition) is created by associating an
identifier (a symbol) with an integer expression or some text.
•Symbols do not reserve storage.
•Equal-Sign Directive
name = expression
expression is a 32-bit integer (expression or constant)
may be redefined
name is called a symbolic constant
• Current Location Counter : the symbol $, is the current location counter,
that returns offset of current location:
selfPtr DWORD $
• This statement declares a variable named selfPtr and initializes it with the variable’s offset
value.
• Symbolic constant