Professional Documents
Culture Documents
Ends myStruct
Structure variable:
structVar myStruct ? ;creates structure variable
Acceccing structure:
MOV [structVar.var1], 20 ;move 20 in var1 in mystruct
Segment Directive
The SEGMENT directive identifies the start of a memory segment and ENDS identifies
the end of a segment when full-segment definitions are in use.
Syntax:
<logical-segment_name> SEGMENT
..
..
<logical-segment_name> ENDS
E.g
mySegment SEGMENT
Mov Ax,BX
..
..
mySegment ENDS
Assume Directive
The ASSUME statement tells the assembler what names have been chosen for
the code, data, extra, and stack segments.
Without the ASSUME statement, the assembler assumes nothing and
automatically uses a segment override prefix on all instructions that address
memory data.
The ASSUME statement is only used with full-segment definitions
Syntax:
ASSUME <Physical-Segment>:<logica-segment_name>
E.g:
mySegment SEGMENT
ASSUME CS : mySegment ;Code segment is initialized to mySegment
Mov AX,BX
mySegment ENDS
Memory Organization
The assembler uses two basic formats for developing software:
.CODE
Designates the beginning of the CODE segment in the program.
.DATA
Designates the beginning of the DATA segment in the program
.STACK
Defines STACK segment in the program.
Syntax : .STACK [memory-size] ;memory-size is optional
Default memory size for stack segment is 1KB.
Initializes Stack Segment(SS), Stack Pointer(SP) and Base Pointer(BP).
Simplified Segment Directives
.STARTUP
Designates the start of the execution of the problem (similar to main() in C).
Loads DATA segment and EXTRA segment.
If the .STARTUP directive is used, the MOV AX,@DATA followed by MOV DS,AX
statements can be eliminated.
The .STARTUP directive also eliminates the need to store the starting address next
to the END label.
.EXIT
The .EXIT 0 directive returns to DOS with an error code of 0 (no error).
If no parameter is added to .EXIT, it still returns to DOS, but the error code is not
defined.
Object file1
.obj
Object file3
.obj
Modular Programming (CONT..)
The PUBLIC and EXTRN directives are very important to modular
programming because they allow communications between modules.
We use PUBLIC to declare that labels of code, data, or entire
segments are available to other program modules.
EXTRN (external) declares that labels are external to a module.
The PUBLIC directive is placed in the opcode field of an assembly
language statement to define a label as public, so that the label can
be used (seen by) by other modules.
The label declared as public can be a jump address, a data address,
or an entire segment.
When segments are made public, they are combined with other public
segments that contain data with the same segment name.
Modular Programming (CONT..)
Placing MACRO Definitions in Their Own Module:
Macro definitions can be placed in the program file, or they can be
placed in their own macro module.
A file can be created that contains only macros to be included with
other program files.
We use the INCLUDE directive to indicate that a program file will
include a module that contains external macro definitions.
When macro sequences are placed in a file (often with the extension
INC or MAC), they do not contain PUBLIC statements as does a library.
Modular Programming (CONT..)
Example MyFun.inc file
.MODEL SMALL
SUM MACRO X,Y
.DATA
.STACK MOV AX, X
MOV BX, Y
.CODE ADD AX, BX
INCLUDE MyFun.inc ;include myFun file
ENDM
.STARTUP
SUM 5,10
.EXIT
END
Conditional Assembly (or Controlled Expansion)
Conditional assembly language statements allow portions of a program to be
assembled if a condition is met.
These are useful for tailoring software to an application
Following table shows the forms used for IF statement in the conditional
assembly.
Statement Function
IF If the expression is true
IFB If argument is blank
IFE If the expression is not true
IFDEF If the label has been defined
IFNB If argument is not blank
IFNDEF If the label has not been defined
IFIDN If argument 1 equals argument 2
IFDIFWWW If argument 1 does not equal to
argument 2