SlideShare ist ein Scribd-Unternehmen logo
1 von 20
PROCEDURES & MACROS
Procedures
• While writing programs, sometimes it may be required
to use same set of instructions repeatedly.
• If these instructions are actually written again & again,
the program size increases and occupies more memory
space.
• To avoid this, these instructions can be written as a
separate program (subprogram) and whenever this set
of instructions is required, an instruction can be
written in the main program CALL this subprogram.
• This saves the memory space.
• A subprogram which is called from the main program
to execute certain set of instructions is called
subroutine or procedure.
Procedures
• Declaring PROCEDURES:
• The syntax for procedure declaration:
• name PROC [NEAR/FAR]
; Instructions of the procedures
; are written here.
RET
• name ENDP
Procedures
• Example:
Delay PROC
MOV CX,COUNT
AGAIN: NOP
LOOP AGAIN
RET
Delay ENDP
Procedures
• A procedure in 8086 can be accessed with a CALL &
RET instruction.
• CALL instruction: This performs two operations
1. Saves the return address or the address of the
instruction next to the CALL instruction on the stack.
Return address is the address where the program will
return to after the procedure completes execution.
– If the call to procedure is in the same code segment, i.e. a
near CALL, then only the contents of IP are pushed on the
stack.
– If the call to procedure is in another code segment, i.e. a
far CALL, then the contents of IP as well as CS are pushed
on the stack.
2. It loads the IP & CS register with a new starting
address of the procedure and then branches to the
procedure.
Procedures
• RET instruction:
• When 8086 executes a CALL instruction, it
stores the return address of the CALLing
routine on the stack.
• A RET instruction at the end of the procedure
copies the return address stored on the stack
back into the CS and IP registers and then
returns execution to the main program.
Procedures
• Passing Parameters to procedures:
• Procedures may require input data or constants for
their execution.
• Their data or constants may be passed to the
procedure by the main program or some procedures
may access the readily available data of constants
available in memory.
• Generally following techniques are used to pass input
data/parameter to procedures in assembly language
programs,
1. Using global declared variable
2. Using registers of CPU architecture
3. Using memory locations
4. Using stack
Example : Using registers
CODE SEGMENT
START: MOV AX, 5555H
MOV BX,7272h
:
:
CALL PROC1
:
:
PROC1 PROCEDURE
:
:
ADD AX,BX
:
:
RET
PROC1 ENDP
CODE ENDS
END START
Procedures
• Re-entrant Procedures :
• A procedure is said to be re-entrant, if it can
be interrupted, used and re-entered without
losing or writing over anything. To be a re-
entrant,
• Procedure must first push all the flags and
registers used in the procedure.
• It should also use only registers or stack to pass
parameters.
• The flow of re-entrant procedure for a multiply
procedure when interrupt procedure is executed,
as shown in the next slide
Procedures
Procedures
• Recursive Procedures:
• A recursive procedure is a procedure which
calls itself.
• Here, the program sets aside a few locations in
stack for the storage of the parameters which
are passed each time the computation is done
and the value is returned.
• Each value returned is then obtained by
popping back from the stack at every RET
instruction when executed at the end of the
procedure.
Program to find the factorial using
recursiondata segment
n db 04h
res dw ?
data ends
code segment
assume cs:code, ds:data
start: mov ax,data
mov ds,ax
mov al,n
mov ah,00h
call fact
int 3
fact proc
cmp ax,01 ;if n=1, fact=1 else fact=n*fact(n-1)
jz exit
push ax
dec ax ;n-1
call fact ;fact(n-1) , RECURSION
pop ax
mul res ;n*fact(n-1)
mov res,ax ;res=factorial
ret
exit:
mov res,01
ret
fact endp
code ends
end start
Advantages of Procedures
• Simple modular programming
• Reduced workload and development time
• Debugging of program and procedure is easier
• Reduction in the size of the main program
• Reuse of procedures in the same program
many times or in another program.
MACROS
• Small sequences of codes of the same pattern
repeated frequently at different places which
perform the same operation on the different
data of the same data type are called MACRO.
• Macro is also called as an Open subroutine.
• When Called, the code written within macro
are executed automatically.
• Macros should be used when it has few
program statements.
• This simplifies the programming process.
MACROS
Advantages
• Simplify and reduce the amount of repetitive
coding
• Reduce errors caused by repetitive coding
• Makes program more readable
• Execution time is less as compared to
procedures as no extra instructions required
Procedure Vs Macros
• Procedure does occupy minimum memory
space than macro.
• In macro machine code is generated for
instructions each time when it is called but in
procedure machine code for instruction is put
only once in the memory
• Procedure is accessed by call Instruction
whereas Macro is accessed with the name
given.
MACROS
Defining Macros
The Directive MACRO indicates the beginning of a
MACRO
Name of the Macro followed by MACRO and arguments if
any are specified.
ENDM is always associated with MACRO which ends the
macro.
General Form :
Macro_name MACRO [Arguement1, arguement2…]
:
:
ENDM
MACROS
Example:
PRINT MACRO MES
MOV AX,09H
LEA DX, MES
INT 21H
ENDM
The above macro is used to display a string
specified in the argument MES on the screen,
when evoked by the main program as given in
the next slide.
MACROS
DATA SEGEMENT
STR DB 0DH,0AH,”Hello World$”
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA, CS:CODE
START: MOV AX, DATA
MOV DS, AX
PRINT STR ; Calls Macro PRINT to display STR
; STR is the parameter passed which is
;taken as MES in the Macro PRINT.
:
:
CODE ENDS
END START

Weitere ähnliche Inhalte

Was ist angesagt?

Address translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhuteAddress translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhuteAniket Bhute
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - VoldWilliam Lee
 
FISL XIV - The ELF File Format and the Linux Loader
FISL XIV - The ELF File Format and the Linux LoaderFISL XIV - The ELF File Format and the Linux Loader
FISL XIV - The ELF File Format and the Linux LoaderJohn Tortugo
 
Something About Dynamic Linking
Something About Dynamic LinkingSomething About Dynamic Linking
Something About Dynamic LinkingWang Hsiangkai
 
Q4.11: Using GCC Auto-Vectorizer
Q4.11: Using GCC Auto-VectorizerQ4.11: Using GCC Auto-Vectorizer
Q4.11: Using GCC Auto-VectorizerLinaro
 
LLVM Backend Porting
LLVM Backend PortingLLVM Backend Porting
LLVM Backend PortingShiva Chen
 
Access modifiers in Python
Access modifiers in PythonAccess modifiers in Python
Access modifiers in PythonSantosh Verma
 
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolExploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolKoan-Sin Tan
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]DEEPIKA T
 
Q2.12: Debugging with GDB
Q2.12: Debugging with GDBQ2.12: Debugging with GDB
Q2.12: Debugging with GDBLinaro
 
LCA14: LCA14-502: The way to a generic TrustZone® solution
LCA14: LCA14-502: The way to a generic TrustZone® solutionLCA14: LCA14-502: The way to a generic TrustZone® solution
LCA14: LCA14-502: The way to a generic TrustZone® solutionLinaro
 
SFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEESFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEELinaro
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginSam Bowne
 
MIPI DevCon 2016: Testing of MIPI High Speed PHY Standard Implementations
MIPI DevCon 2016: Testing of MIPI High Speed PHY Standard ImplementationsMIPI DevCon 2016: Testing of MIPI High Speed PHY Standard Implementations
MIPI DevCon 2016: Testing of MIPI High Speed PHY Standard ImplementationsMIPI Alliance
 
Git Workflow With Gitflow
Git Workflow With GitflowGit Workflow With Gitflow
Git Workflow With GitflowJosh Dvir
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineChun-Yu Wang
 

Was ist angesagt? (20)

Address translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhuteAddress translation-mechanism-of-80386 by aniket bhute
Address translation-mechanism-of-80386 by aniket bhute
 
Class method
Class methodClass method
Class method
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
 
A practical guide to buildroot
A practical guide to buildrootA practical guide to buildroot
A practical guide to buildroot
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
FISL XIV - The ELF File Format and the Linux Loader
FISL XIV - The ELF File Format and the Linux LoaderFISL XIV - The ELF File Format and the Linux Loader
FISL XIV - The ELF File Format and the Linux Loader
 
Something About Dynamic Linking
Something About Dynamic LinkingSomething About Dynamic Linking
Something About Dynamic Linking
 
Q4.11: Using GCC Auto-Vectorizer
Q4.11: Using GCC Auto-VectorizerQ4.11: Using GCC Auto-Vectorizer
Q4.11: Using GCC Auto-Vectorizer
 
LLVM Backend Porting
LLVM Backend PortingLLVM Backend Porting
LLVM Backend Porting
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Access modifiers in Python
Access modifiers in PythonAccess modifiers in Python
Access modifiers in Python
 
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolExploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Q2.12: Debugging with GDB
Q2.12: Debugging with GDBQ2.12: Debugging with GDB
Q2.12: Debugging with GDB
 
LCA14: LCA14-502: The way to a generic TrustZone® solution
LCA14: LCA14-502: The way to a generic TrustZone® solutionLCA14: LCA14-502: The way to a generic TrustZone® solution
LCA14: LCA14-502: The way to a generic TrustZone® solution
 
SFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEESFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEE
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you Begin
 
MIPI DevCon 2016: Testing of MIPI High Speed PHY Standard Implementations
MIPI DevCon 2016: Testing of MIPI High Speed PHY Standard ImplementationsMIPI DevCon 2016: Testing of MIPI High Speed PHY Standard Implementations
MIPI DevCon 2016: Testing of MIPI High Speed PHY Standard Implementations
 
Git Workflow With Gitflow
Git Workflow With GitflowGit Workflow With Gitflow
Git Workflow With Gitflow
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
 

Ähnlich wie Chap6 procedures & macros

Ähnlich wie Chap6 procedures & macros (20)

Chapter 6 notes
Chapter 6 notesChapter 6 notes
Chapter 6 notes
 
Chapter 5 notes new
Chapter 5 notes newChapter 5 notes new
Chapter 5 notes new
 
Chapter 5 notes
Chapter 5 notesChapter 5 notes
Chapter 5 notes
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
 
unit-2.pptx
unit-2.pptxunit-2.pptx
unit-2.pptx
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Introduction to Microcontrollers
Introduction to MicrocontrollersIntroduction to Microcontrollers
Introduction to Microcontrollers
 
Procedure
ProcedureProcedure
Procedure
 
OpenPOWER Application Optimization
OpenPOWER Application Optimization OpenPOWER Application Optimization
OpenPOWER Application Optimization
 
Chapter Seven(1)
Chapter Seven(1)Chapter Seven(1)
Chapter Seven(1)
 
assembler Directives hnotesnnnnnnnn.pptx
assembler Directives hnotesnnnnnnnn.pptxassembler Directives hnotesnnnnnnnn.pptx
assembler Directives hnotesnnnnnnnn.pptx
 
Mod 3.pptx
Mod 3.pptxMod 3.pptx
Mod 3.pptx
 
Unit 4 assembly language programming
Unit 4   assembly language programmingUnit 4   assembly language programming
Unit 4 assembly language programming
 
13 risc
13 risc13 risc
13 risc
 
CPU Architecture
CPU ArchitectureCPU Architecture
CPU Architecture
 
Co&al lecture-07
Co&al lecture-07Co&al lecture-07
Co&al lecture-07
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
class-Stacks.pptx
class-Stacks.pptxclass-Stacks.pptx
class-Stacks.pptx
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
Different addressing mode and risc, cisc microprocessor
Different addressing mode and risc, cisc microprocessorDifferent addressing mode and risc, cisc microprocessor
Different addressing mode and risc, cisc microprocessor
 

Mehr von HarshitParkar6677 (20)

Wi fi hacking
Wi fi hackingWi fi hacking
Wi fi hacking
 
D dos attack
D dos attackD dos attack
D dos attack
 
Notes chapter 6
Notes chapter  6Notes chapter  6
Notes chapter 6
 
Interface notes
Interface notesInterface notes
Interface notes
 
Chapter6 2
Chapter6 2Chapter6 2
Chapter6 2
 
Chapter6
Chapter6Chapter6
Chapter6
 
8086 cpu 1
8086 cpu 18086 cpu 1
8086 cpu 1
 
Notes arithmetic instructions
Notes arithmetic instructionsNotes arithmetic instructions
Notes arithmetic instructions
 
Notes all instructions
Notes all instructionsNotes all instructions
Notes all instructions
 
Notes aaa aa
Notes aaa aaNotes aaa aa
Notes aaa aa
 
Notes 8086 instruction format
Notes 8086 instruction formatNotes 8086 instruction format
Notes 8086 instruction format
 
Misc
MiscMisc
Misc
 
Copy of 8086inst logical
Copy of 8086inst logicalCopy of 8086inst logical
Copy of 8086inst logical
 
Copy of 8086inst logical
Copy of 8086inst logicalCopy of 8086inst logical
Copy of 8086inst logical
 
Chapter3 program flow control instructions
Chapter3 program flow control instructionsChapter3 program flow control instructions
Chapter3 program flow control instructions
 
Chapter3 8086inst stringsl
Chapter3 8086inst stringslChapter3 8086inst stringsl
Chapter3 8086inst stringsl
 
Chapter3 8086inst logical 2
Chapter3 8086inst logical 2Chapter3 8086inst logical 2
Chapter3 8086inst logical 2
 
Chapter 3 8086 ins2 math
Chapter 3 8086 ins2 mathChapter 3 8086 ins2 math
Chapter 3 8086 ins2 math
 
Chap3 program flow control instructions
Chap3 program flow control instructionsChap3 program flow control instructions
Chap3 program flow control instructions
 
Chap3 8086 logical
Chap3 8086 logicalChap3 8086 logical
Chap3 8086 logical
 

Kürzlich hochgeladen

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 

Kürzlich hochgeladen (20)

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 

Chap6 procedures & macros

  • 2. Procedures • While writing programs, sometimes it may be required to use same set of instructions repeatedly. • If these instructions are actually written again & again, the program size increases and occupies more memory space. • To avoid this, these instructions can be written as a separate program (subprogram) and whenever this set of instructions is required, an instruction can be written in the main program CALL this subprogram. • This saves the memory space. • A subprogram which is called from the main program to execute certain set of instructions is called subroutine or procedure.
  • 3. Procedures • Declaring PROCEDURES: • The syntax for procedure declaration: • name PROC [NEAR/FAR] ; Instructions of the procedures ; are written here. RET • name ENDP
  • 4. Procedures • Example: Delay PROC MOV CX,COUNT AGAIN: NOP LOOP AGAIN RET Delay ENDP
  • 5. Procedures • A procedure in 8086 can be accessed with a CALL & RET instruction. • CALL instruction: This performs two operations 1. Saves the return address or the address of the instruction next to the CALL instruction on the stack. Return address is the address where the program will return to after the procedure completes execution. – If the call to procedure is in the same code segment, i.e. a near CALL, then only the contents of IP are pushed on the stack. – If the call to procedure is in another code segment, i.e. a far CALL, then the contents of IP as well as CS are pushed on the stack. 2. It loads the IP & CS register with a new starting address of the procedure and then branches to the procedure.
  • 6. Procedures • RET instruction: • When 8086 executes a CALL instruction, it stores the return address of the CALLing routine on the stack. • A RET instruction at the end of the procedure copies the return address stored on the stack back into the CS and IP registers and then returns execution to the main program.
  • 7. Procedures • Passing Parameters to procedures: • Procedures may require input data or constants for their execution. • Their data or constants may be passed to the procedure by the main program or some procedures may access the readily available data of constants available in memory. • Generally following techniques are used to pass input data/parameter to procedures in assembly language programs, 1. Using global declared variable 2. Using registers of CPU architecture 3. Using memory locations 4. Using stack
  • 8. Example : Using registers CODE SEGMENT START: MOV AX, 5555H MOV BX,7272h : : CALL PROC1 : : PROC1 PROCEDURE : : ADD AX,BX : : RET PROC1 ENDP CODE ENDS END START
  • 9. Procedures • Re-entrant Procedures : • A procedure is said to be re-entrant, if it can be interrupted, used and re-entered without losing or writing over anything. To be a re- entrant, • Procedure must first push all the flags and registers used in the procedure. • It should also use only registers or stack to pass parameters. • The flow of re-entrant procedure for a multiply procedure when interrupt procedure is executed, as shown in the next slide
  • 11. Procedures • Recursive Procedures: • A recursive procedure is a procedure which calls itself. • Here, the program sets aside a few locations in stack for the storage of the parameters which are passed each time the computation is done and the value is returned. • Each value returned is then obtained by popping back from the stack at every RET instruction when executed at the end of the procedure.
  • 12. Program to find the factorial using recursiondata segment n db 04h res dw ? data ends code segment assume cs:code, ds:data start: mov ax,data mov ds,ax mov al,n mov ah,00h call fact int 3
  • 13. fact proc cmp ax,01 ;if n=1, fact=1 else fact=n*fact(n-1) jz exit push ax dec ax ;n-1 call fact ;fact(n-1) , RECURSION pop ax mul res ;n*fact(n-1) mov res,ax ;res=factorial ret exit: mov res,01 ret fact endp code ends end start
  • 14. Advantages of Procedures • Simple modular programming • Reduced workload and development time • Debugging of program and procedure is easier • Reduction in the size of the main program • Reuse of procedures in the same program many times or in another program.
  • 15. MACROS • Small sequences of codes of the same pattern repeated frequently at different places which perform the same operation on the different data of the same data type are called MACRO. • Macro is also called as an Open subroutine. • When Called, the code written within macro are executed automatically. • Macros should be used when it has few program statements. • This simplifies the programming process.
  • 16. MACROS Advantages • Simplify and reduce the amount of repetitive coding • Reduce errors caused by repetitive coding • Makes program more readable • Execution time is less as compared to procedures as no extra instructions required
  • 17. Procedure Vs Macros • Procedure does occupy minimum memory space than macro. • In macro machine code is generated for instructions each time when it is called but in procedure machine code for instruction is put only once in the memory • Procedure is accessed by call Instruction whereas Macro is accessed with the name given.
  • 18. MACROS Defining Macros The Directive MACRO indicates the beginning of a MACRO Name of the Macro followed by MACRO and arguments if any are specified. ENDM is always associated with MACRO which ends the macro. General Form : Macro_name MACRO [Arguement1, arguement2…] : : ENDM
  • 19. MACROS Example: PRINT MACRO MES MOV AX,09H LEA DX, MES INT 21H ENDM The above macro is used to display a string specified in the argument MES on the screen, when evoked by the main program as given in the next slide.
  • 20. MACROS DATA SEGEMENT STR DB 0DH,0AH,”Hello World$” DATA ENDS CODE SEGMENT ASSUME DS:DATA, CS:CODE START: MOV AX, DATA MOV DS, AX PRINT STR ; Calls Macro PRINT to display STR ; STR is the parameter passed which is ;taken as MES in the Macro PRINT. : : CODE ENDS END START