Difference between Macro & Function

Macro and Function Comparison


Q.        Write a difference between MACRO and FUNCTION with example ? ----(7m)

Sr. No.MACRO   FUNCTIONS
1

MACROS are preprocessed before compilator or assembling.       

Functions are used after compilation or assemblIng.
2Code length is get increases as it performs expansion Code length will remain same as it is not performing expansion.
3Program with MACRO expansion  Performs in faster way because of  Sequential execution.Program with function calls performs in slower way because of involvement of stack.
4MACRO’s are Time efficient      Functions are not time efficient
5It is useful where small code appears several timesIt is useful where large code appears several several times.  
6Because of expansion it requires more memoryIt requires less memory

MACRO Example in assembly Language :-

MACRO Definition :-                                                MACRO Call :-

MACRO                                                         DELAY

DELAY                                                           (Macro call expans main program

MOVER AREG, = ‘0’                                      by replacing 2 instructions

MOVEM BREG, LOC                                                in definition of macro )

MEND

Function Example in assembly Language :-

Function Definition -                         Function call –

DELAY:                                              ACALL DELAY

MOVER AREG, = ‘0’                          ( Function call transfers program control to function name

MOVEM BREG, LOC                                    and after function execution for RET instruction

RET                                                     control again transferred back to main program.


References

Prof Dipak Pawar, Team WikiNote Pune


Last modified: Friday, 20 September 2019, 12:17 AM