0% found this document useful (0 votes)
33 views8 pages

Experiment 5

The document discusses procedures and macros in 8086 assembly language. It defines procedures as reusable blocks of code that can reduce program size and make debugging easier. Near procedures reside in the same code segment as the calling code, while far procedures are in a different segment. The PROC and ENDP directives mark the start and end of a procedure. CALL pushes the return address and jumps to the procedure, while RET pops the return address to return to the calling code. Macros allow code to be reused by substituting macro parameters. The document provides examples of 8086 assembly code demonstrating procedures and macros.

Uploaded by

Samrudhi Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views8 pages

Experiment 5

The document discusses procedures and macros in 8086 assembly language. It defines procedures as reusable blocks of code that can reduce program size and make debugging easier. Near procedures reside in the same code segment as the calling code, while far procedures are in a different segment. The PROC and ENDP directives mark the start and end of a procedure. CALL pushes the return address and jumps to the procedure, while RET pops the return address to return to the calling code. Macros allow code to be reused by substituting macro parameters. The document provides examples of 8086 assembly code demonstrating procedures and macros.

Uploaded by

Samrudhi Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

STME, NMIMS Navi Mumbai Campus

Computer Engineering Class: - B Tech (CE) Sem IV


Subject: - Microprocessor and Academic Year: - 2023-24
Microcontroller

Experiment: - 5
Name: Sarvesh Patil Roll No. : A173
Sap ID: 70022200488
Date of Performance: Date of Submission:

Aim: Demonstration of procedures and macros


(a) Write a neatly commented 8086 ALP to demonstrate use of a procedure that
generates delay.
(b) Write a neatly commented 8086 ALP to demonstrate creation and use of a macro
Apparatus Required: Personal Computer.
Software required: - emu8086.
Theory:
A procedure is group of instructions that usually performs one task. It is a reusable section of a
software program which is stored in memory once but can be used as often as necessary.
A procedure can be of two types. 1) Near Procedure 2) Far Procedure
Near Procedure: A procedure is known as NEAR procedure if is written(defined) in the same code
segment which is calling that procedure. Only Instruction Pointer(IP register) contents will be
changed in NEAR procedure.
FAR procedure : A procedure is known as FAR procedure if it is written (defined) in the different
code segment than the calling segment. In this case both Instruction Pointer(IP) and the Code
Segment(CS) register content will be changed.
Directives used for procedure : PROC directive: The PROC directive is used to identify the start of a
procedure. The PROC directive follows a name given to the procedure. After that, the term FAR and
NEAR is used to specify the type of the procedure.
ENDP Directive: This directive is used along with the name of the procedure to indicate the end of a
procedure to the assembler. The PROC and ENDP directive are used to bracket a procedure.
CALL instruction and RET instruction :
CALL instruction : The CALL instruction is used to transfer execution to a procedure.It performs two
operation. When it executes, first it stores the address of instruction after the CALL instruction on the
stack. Second it changes the content of IP register in case of Near call and changes the content of IP
register and cs register in case of FAR call. There are two types of calls. 1)Near Call or Intra segment
call. 2) Far call or Inter Segment call
Operation for Near Call : When 8086 executes a near CALL instruction, it decrements the stack
pointer by 2 and copies the IP register contents on to the stack. Then it copies address of first
instruction of called procedure.
SP <- SP-2
STME, NMIMS Navi Mumbai Campus
Computer Engineering Class: - B Tech (CE) Sem IV
Subject: - Microprocessor and Academic Year: - 2023-24
Microcontroller

IP -> stores onto stack


IP <- starting address of a procedure.

Operation of FAR CALL: When 8086 executes a far call, it decrements the stack pointer by 2 and
copies the contents of CS register to the stack. It the decrements the stack pointer by 2 again and
copies the content of IP register to the stack. Finally, it loads cs register with base address of segment
having procedure and IP with address of first instruction in procedure.
SP <- SP-2
CS contents -> stored on stack
SP <- SP-2
IP contents -> stored on stack
CS <- Base address of segment having procedure
IP <- address of first instruction in procedure.

RET instruction : The RET instruction will return execution from a procedure to the next instruction
after call in the main program. At the end of every procedure RET instruction must be executed.
Operation for Near Procedure : For NEAR procedure ,the return is done by replacing the IP register
with a address popped off from stack and then SP will be incremented by 2.
IP <- Address from top of stack
SP <- SP+2

Operation for FAR procedure : IP register is replaced by address popped off from top of stack,then SP
will be incremented by 2.The CS register is replaced with a address popped off from top of stack.
Again SP will be incremented by 2.
IP <-Address from top of stack
SP <-SP+2
CS <-Address from top of stack
SP <-SP+2

Advantages and Disadvantages of using procedure :


Advantages :
1) Allows to save memory space.
2) Program development becomes easier.
3) Debugging of errors in program become easy.
4) Reduced size of program
5) Reusability of procedure.

Disadvantages :
1) CALL and RET instructions are always required to integrate with procedures.
2) Requires the extra time to link procedure and return from it.
STME, NMIMS Navi Mumbai Campus
Computer Engineering Class: - B Tech (CE) Sem IV
Subject: - Microprocessor and Academic Year: - 2023-24
Microcontroller

3) For small group of instructions, linking and returning back time more than the execution time,
hence for small group of instructions procedures cannot be preferred.
STME, NMIMS Navi Mumbai Campus
Computer Engineering Class: - B Tech (CE) Sem IV
Subject: - Microprocessor and Academic Year: - 2023-24
Microcontroller
STME, NMIMS Navi Mumbai Campus
Computer Engineering Class: - B Tech (CE) Sem IV
Subject: - Microprocessor and Academic Year: - 2023-24
Microcontroller

Code and Output:


STME, NMIMS Navi Mumbai Campus
Computer Engineering Class: - B Tech (CE) Sem IV
Subject: - Microprocessor and Academic Year: - 2023-24
Microcontroller
STME, NMIMS Navi Mumbai Campus
Computer Engineering Class: - B Tech (CE) Sem IV
Subject: - Microprocessor and Academic Year: - 2023-24
Microcontroller
STME, NMIMS Navi Mumbai Campus
Computer Engineering Class: - B Tech (CE) Sem IV
Subject: - Microprocessor and Academic Year: - 2023-24
Microcontroller

You might also like