You are on page 1of 3

STRUCTURE OF AN ASSEMBLY LANGUAGE PROGRAM

TITLE MYPROG.ASM
DOSSEG
.MODEL SMALL
.STACK 0100h
.DATA
X
DB
.CODE
MOV AX, @DATA
MOV DS, AX

Kamusta,

MOV AH, 09h


MOV DX, OFFSET X
INT 21h

AdU!$

;calls interrupt service 09

MOV AX, 4C00h


INT 21h
END

COMPILE WITH: TASM <filename>


CONNECT WITH: TLINK <filename>
RUN WITH: <filename>
NOTE: <filename>s extension file must
not be included.

1.

DISPLAYING A CHARACTER ON SCREEN (A)

Code

Output

TITLE MYPROG.ASM
DOSSEG
.MODEL SMALL
.STACK 0100h
.DATA
.CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 02h
MOV DL, A
INT 21h

;calls interrupt service 02

MOV AX, 4C00h


INT 21h
END
2.

DISPLAYING A CHARACTER ON SCREEN (a)

Code

Output

TITLE MYPROG.ASM
DOSSEG
.MODEL SMALL
.STACK 0100h
.DATA
.CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 02h
MOV DL, a
INT 21h
MOV AX, 4C00h
INT 21h
END

;calls interrupt service 02

3.

USING CONTROL CHARACTERS IN A SCREEN DISPLAY (0A & 0D)

Code

Output

TITLE MYPROG.ASM
DOSSEG
.MODEL SMALL
.STACK 0100h
.DATA
.CODE
MOV AX, @DATA
MOV DS, AX
MOV
MOV
INT
MOV
INT
MOV
INT
MOV
INT
MOV
INT
MOV
INT
MOV
INT

AH,
DL,
21h
DL,
21h
DL,
21h
DL,
21h
DL,
21h
DL,
21h
DL,
21h

02h
A

;calls interrupt service 02

0Ah

;line feed

0Dh

;carriage return

D
0Ah

;line feed

0Dh

;carriage return

MOV AX, 4C00h


INT 21h
END
4.

DISPLAYING THE SAME CHARACTER THIRTY TIMES USING LOOP ON SCREEN

Code

Output

TITLE MYPROG.ASM
DOSSEG
.MODEL SMALL
.STACK 0100h
.DATA
.CODE
MOV AX, @DATA
MOV DS, AX
MOV CX, 001Eh
;setting number of loops, 001E-Hexadecimal=30
MOV AH, 02h
;calls interrupt service 02
MOV DL, z
A:
INT 21h
LOOP A
;go to label A
MOV AX, 4C00h
INT 21h
END

EXERCISE 1
Code

Output

TITLE MYPROG.ASM
DOSSEG
.MODEL SMALL
.STACK 0100h
.DATA
A
DB
B
DB
C
DB
.CODE
MOV AX, @DATA
MOV DS, AX
MOV
MOV
INT
MOV
MOV
INT
MOV
INT
MOV
MOV
INT
MOV
MOV
INT
MOV
INT
MOV
MOV
INT

AH,
DX,
21h
AH,
DL,
21h
DL,
21h
AH,
DX,
21h
AH,
DL,
21h
DL,
21h
AH,
DX,
21h

Shenel A. Sambrano$
2nd year-CS$
09**-***-****$

09h
OFFSET A

;calls interrupt service 09

02h
0Ah

;calls interrupt service 02


;line feed

0Dh

;carriage return

09h
OFFSET B

;calls interrupt service 09

02h
0Ah

;calls interrupt service 02


;line feed

0Dh

;carriage return

09h
OFFSET C

;calls interrupt service 09

MOV AX, 4C00h


INT 21h
END

Reserved Words
A. Instructions
Statements translated to machine language (i.e. MOV, ADD, SUB, MUL, DIV, INC, DEC, LOOP, CMP)
B. Directives
Give information to the assembler.
o
TITLE title for the program (max of 60 characters).
o
DOSSEG tells the compiler to ignore all other request and to adopt the DOS segment sequence stack, data, and code.
o
.MODEL specifies and initializes the memory model before defining any segment.
MEMORY MODEL
Tiny
Small
Medium
Compact
Large

C.
D.

NO. OF DATA SEGMENT


0
1
1
More than 1
More than 1

NO. OF CODE SEGMENT


0
1
More than 1
1
More than 1

o
o

.STACK defines the size of the stack (default: 1,024 bytes but you can overrule).
.DATA defines and marks the beginning of data segment.
DIRECTIVES LENGTH(bytes)
DESCRIPTION
DB
1
Define Byte
DW
2
Define Word
DD
4
Define Doubleword
DF
6
Define Farword
DQ
8
Define Quadword
DT
10
Define Tenbytes

o
o

.CODE defines and marks the code segment which consists of a set of instructions.
END placed at the last line of the source code.

Operators
Used at assembly time to affect the value of the operand (i.e. OFFSET, SIZE, LENGTH, PTR, MOD, +, -, *, /).
Pre-defined symbols
Symbols that return information to your program (i.e. @data, @model).