📜  宏和过程的区别

📅  最后修改于: 2021-09-14 02:40:14             🧑  作者: Mango

汇编语言是一种常用的中级编程语言,用于微处理器编程。这个宏和过程是汇编中的两个概念,通过它实现模块化编程。那么现在让我们了解一下宏和过程是如何不同的。

1. 宏:
宏是一组指令,程序员可以使用它的名字在程序中的任何地方使用它。主要用于实现模块化编程。因此,在宏的帮助下,可以多次使用相同的指令集。无论在哪里使用宏的标识符,它都会在编译期间由实际定义的指令替换,因此不会发生调用和返回。

宏的语法:

%macro macro_name number_of_parameters

%endmacro

2. 程序:
过程也类似于宏,但是当宏对小指令集有用时,它们用于大指令集。它包含一组执行特定任务的指令。它包含三个主要部分,即标识过程的过程名称、包含指令集的过程体和表示返回语句的RET 语句。与宏不同,过程遵循调用-返回方法,从而实现真正的模块化。

程序语法:

procedure_name :
procedure body
 ….......................
RET

调用过程

CALL procedure_name

过程执行后,使用 RET 语句将控制权传递给调用过程。

宏和过程的区别:

S.No. MACRO PROCEDURE
01. Macro definition contains a set of instruction to support modular programming. Procedure contains a set of instructions which can be called repetitively which can perform a specific task.
02. It is used for small set of instructions mostly less than ten instructions. It is used for large set of instructions mostly more than ten instructions.
03. In case of macro memory requirement is high. In case of procedure memory requirement is less.
04. CALL and RET instruction/statements are not required in macro. CALL and RET instruction/statements are required in procedure.
05. Assembler directive MACRO is used to define macro and assembler directive ENDM is used to indicate the body is over. Assembler directive PROC is used to define procedure and assembler directive ENDP is used to indicate the body is over.
06. Execution time of macro is less than it executes faster than procedure. Execution time of procedures is high as it executes slower than macro.
07. Here machine code is created multiple times as each time machine code is generated when macro is called. Here machine code is created only once, it is generated only once when the procedure is defined.
08. In a macro parameter is passed as part of statement that calls macro. In a procedure parameters are passed in registers and memory locations of stack.
09. Overhead time does not take place as there is no calling and returning. Overhead time takes place during calling procedure and returning control to calling program.