Lecture 6 Assembly Language Programming - Introduction
Lecture 6 Assembly Language Programming - Introduction
The TITLE directive marks the entire line as a comment. You can put anything you want on this
line.
The INCLUDE directive copies necessary definitions and setup information from a text file
named Irvine32.inc, located in the assembler’s INCLUDE directory
The .code directive marks the beginning of the code segment, where all executable statements in a
program are located.
The PROC directive identifies the beginning of a procedure.
The MOV instruction moves (copies) the integer 10000h to the EAX register.
The ADD instruction adds 40000h to the EAX register.
The SUB instruction subtracts 20000h from the EAX register.
The CALL statement calls a procedure that displays the current values of the CPU registers.
The exit statement (indirectly) calls a predefined MS-Windows function that halts the program.
The ENDP directive marks the end of the main procedure
The END main directive marks the last line of the program to be assembled.
Program Output
Assembly language programs structure
Defining Segments One important function of assembler directives is to define program sections, or
segments.
The .DATA directive identifies the area of a program containing variables:
.data
The .CODE directive identifies the area of a program containing instructions:
.code
The .STACK directive identifies the area of a program holding the runtime stack, setting its size:
.stack 100h
Name The optional name assigned to a variable must conform to the rules for identifiers, When
you declare an integer variable by assigning a label to a data allocation directive, the assembler
allocates memory space for the integer. The variable’s name becomes a label for the memory
space.
Directive The directive in a data definition statement can be BYTE, WORD, DWORD, SBYTE,
SWORD, or any of the types listed in the following table
In addition, it can be any of the legacy data definition directives shown in the following table
Data Initialization
You can initialize variables when you declare them with constants or expressions that evaluate to
constants. The assembler generates an error if you specify an initial value too large for the variable
type.
A ? in place of an initializer indicates you do not require the assembler to initialize the variable.
The assembler allocates the space but does not write in it.
o Use ? for buffer areas or variables your program will initialize at run time.
You can declare and initialize
itialize variables in one step with the data directives, as these examples
show.