Assembly Language
programming of 8086
Assemble-Linker-Loader
a compiler
• When the source language is a high-level
• language such as Java or C and the target
• language is either a numerical machine
• language or a symbolic representation for
one,
• the translator is called a compiler
Procedures and Macros
Procedures
• The procedure is a group of instructions stored as a separate
program in the memory and it is called from the main
program whenever required using CALL instruction.
• For calling the procedure we have to store the return address
(next instruction address followed by CALL) onto the stack.
• At the end of the procedure RET instruction used to return
the execution to the next instruction in the main program by
retrieving the address from the top of the stack.
• Machine codes for the procedure instructions put only once
in memory.
• The procedure can be defined anywhere in the program using
assembly directives PROC and ENDP.
Procedures
Procedures
The four major ways of passing parameters to and from a procedure are:
1. In registers
2. In dedicated memory location accessed by name
3 .With pointers passed in registers
4. With the stack
• The type of procedure depends on where the procedure is stored in the
memory.
• If it is in the same code segment where the main program is stored the it
is called near procedure otherwise it is
• referred to as far procedure.
• For near procedure CALL instruction pushes only the IP register contents
on the stack, since CS register contents
• remains unchanged for main program.
• But for Far procedure CALL instruction pushes both IP and CS on the stack.
Syntax
Syntax: Cont..
Procedure name PROC near far procedure:
instruction 1
instruction 2 Procedures segment
RET Assume CS : Procedures
Procedure name ENDP
ADD2 PROC far
Example: ADD AX,BX
near procedure: RET ADD2 ENDP
ADD2 PROC near
ADD AX,BX Procedures ends
RET
ADD2 ENDP
• Depending on the characteristics the
procedures are two types
1. Re-entrant Procedures
2. Recursive Procedures
Reentrant Procedures
Recursive Procedure
• Parameters Passing in procedure
– Passing parameters through the Registers
– Passing parameters on the stack
– Passing parameters in an argument
Procedures
Advantages
• The machine codes for the group of
instructions in the procedure only have to be
put once.
Disadvantages
• Need for stack
• Overhead time required to call the procedure
and return to the calling program.
Macros
• A macro is a group of repetitive instructions in a
program which are codified only once and can be
used as many times as necessary.
• A macro can be defined anywhere in program using
the directives MACRO and ENDM
• Each time we call the macro in a program, the
assembler will insert the defined group of instructions
in place of the call.
• The assembler generates machine codes for the group
of instructions each time the macro is called.
• Using a macro avoids the overhead time involved in
calling and returning from a procedure.
Syntax
Syntax of macro:
macroname MACRO
instruction1
instruction2
.
.
ENDM
Macros
Advantages
• Macro avoids overhead time involving in
calling and returning from a procedure.
Disadvantages
• Generating in line code each time a macro is
called is that this will make the program take
up more memory than using a procedure.