You are on page 1of 16

Module 2

Instruction set and Assembly Language Programming


Introduction to Assembly Language Programming

Assembler Directives

Macros and Procedure

Syllabus Addressing Modes

Instruction Set

Mixed Mode Programming


Introduction to ALP
Assembler
•  Assembly programming is
low-level programming.
• An assembler is used to
translate the assembly
code into the
machine code for the target
computer.
• Low Level directly interact with target machine
architecture.
• Required Low memory
Features of ALP • Faster Execution
• TSR Programs (Terminate and Stay Resident ) are
written in Assembly Language
• System software's are written in Assembly Language
• Easy Hardware interaction
• Support of Mixed Mode Programming
.MODEL SMALL
.STACK
.DATA
Structure of Assembly .CODE
Language Programming .STARTUP
\\STATEMETS
.EXIT
END
• Assembly language consists of two types of

Assembler
statements:
1. Executable statements- These are the
statements to be executed by the
processor. It consists of the entire
instruction set of 8086.
2. Assembler directives- These are the
statements that direct the assembler to do
something. As the name says, it directs the
Directives
assembler to do a task.
• The specialty of these statements
is that they are effective only
during the assembly of a program
but they do not generate any code
that is machine executable.
1. Model Small:
Simplified segment directives. Initialize a memory model, using the .MODEL directive, before declaring
any segment.

The format of the .MODEL directive is:


.MODEL memory-model
List Assembler • The memory-model may be TINY, SMALL, MEDIUM, COMPACT, LARGE, HUGE or
Directives FLAT
.CODE- This assembler directive indicates the beginning of the code segment. Its format
is as follows: .CODE [name] The name in this format is optional.
.DATA- This directive indicates the beginning of the data segment.
.STACK- This directive is used for defining the stack. Its format is as follows: .STACK
[size]
List Assembler ASSUME- The directive is used for telling the assembler the name of the logical
segment which should be used.
Directives • The ASSUME directive is used to tell the assembler that the name of the logical
segment should be used for a specified segment. The 8086 works directly with
only 4 physical segments: a Code segment, a data segment, a stack segment, and
an extra segment.
• Example:
• ASSUME CS:CODE ; This tells the assembler that the logical segment named
CODE contains the instruction statements for the program and should be treated
as a code segment.
• ASSUME DS:DATA ; This tells the assembler that for any instruction which
refers to a data in the data segment, data will found in the logical segment
DATA.
• Define Byte [DB]- This directive defines the byte type variable.
• Define Word [DW]- The DW directive defines items that are one word (two bytes) in
List Assembler length.
Directives • Define Double word [DD]- It defines the data items that are a double word (four bytes) in
length.
• Define Quad word [DQ]- This directive is used to tell the assembler to declare variable 4
words in length or to reserve 4 words of storage in memory.
• Define Ten bytes [DT]- It is used to define the data items that are 10 bytes long.
• EQU: This EQU directive is used to give a name to some value or to
a symbol. Each time the assembler finds the name in the program,
it will replace the name with the value or symbol you given to that
name.
Example: FACTOR EQU 03H
List Assembler ADD AL, FACTOR

Directives
• PROC: The PROC directive is used to identify the start of a procedure. The
term near or far is used to specify the type of the procedure.
• ENDP – End of Procedure
• END - End Program
• ENDS - End Segment
• Macro: To identify macro definition
• MEND- End of Macro definition
1. MOV AH,09 ;TO DISPLAY MSG ON SCREEN
LEAD DX, MSG
INT 21H
Important 2. MOV AH,01 ;ENTER CHAR FROM USER
Interrupt and INT 21H
Functions RETURN: AL: ASCII VALUE OF ENTERED KEY
3. MOV AH,02 ;DISPLAY CHAR
MOV DL,AL
INT 21H
Differentiate between Near and Far Procedure
Near Call Far Call
A near call refers a procedure which is in the same A Far call refers a procedure which is in different code
code segment. segment
It is also called Intra-segment call. It is also called Inter-segment call
A Near Call replaces the old IP with new IP A FAR replaces CS & IP with new CS & IP.
It uses keyword near for calling procedure. It uses keyword far for calling procedure.
Less stack locations are required More stack locations are required.
Macros Procedure

Every time macro call, it is replaced by definition Written once and call many times

Program takes up more memory space. Program takes up comparatively less memory space.

No transfer of program counter. Transferring of program counter is required.

Difference No overhead of using stack for transferring control Overhead of using stack for transferring control
Between Macros
and Procedure
Execution is fast Execution is comparatively slow.

Overhead of using Macroprocessor No overhead

Macros are used when repeated group of Procedure is used when repeated group of
instruction is too short. instructions is quite large.
Questions?
• Define Assembler Directives. List and explain various assembler
directives.
• Differentiate between Macros and Procedure. Also write when to use
Macros and When to use procedure in the program.
• Write ALP to convert ASCII to BCD or BCD to ASCII.
• Apply macros and procedure in the program to design calculator using
ALP.
Any Query?

• Thank you.

You might also like