Hi, I have doubt on my answer in regards to the example for the coding part. I know my definition part should be okay, but I have doubt on my example part to show the difference between the Macro and the procedure. Can you please take a look at my answer and let me know if my answer is the best answer for this question? Thanks:)

1.Briefly explain the differnce between a marco and a procedure and
give an example.

Answer:
-------

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.

The main difference between a macro and a procedure is that in the macro the passage of parameters is possible and in the
procedure it is not, this is only applicable for the MASM - there are other programming languages which do allow it.
At the moment the macro is executed each parameter is substituted by the name or value specified at the time of the call.

We can say then that a procedure is an extension of a determined program, while the macro is a module with specific
functions which can be used by different programs.

Another difference between a macro and a procedure is the way of calling each one, to call a procedure the use of a
directive is required, on the other hand the call of macros is done as if it were an assembler instruction.
Example of procedure:
For example, if we want a routine which adds two bytes stored in AH and AL each one, and keep the addition in the BX register:


Adding Proc Near ; Declaration of the procedure
Mov Bx, 0 ; Content of the procedure
Mov B1, Ah
Mov Ah, 00
Add Bx, Ax
Ret ; Return directive
Add Endp ; End of procedure declaration

and an example of Macro:

Position MACRO Row, Column
PUSH AX
PUSH BX
PUSH DX
MOV AH, 02H
MOV DH, Row
MOV DL, Column
MOV BH, 0
INT 10H
POP DX
POP BX
POP AX
ENDM

The main difference between a macro and a procedure is that in the macro the passage of parameters is possible and in the
procedure it is not

That isn't true of any major computer language that I know of. Procedures in every language can accept parameters. In assembly language you can store the parameters in registers, push them one the stack or some combination of the two before calling the procedure.

Macros are a different breed of cat entirely. Whereas procedures are imple-mented by the use of CALL and RET instructions built right into the instruction set, macros are a trick of the assembler, and do not depend on any particular instruction or group of instructions. Most simply put, a macro is a label that stands for some sequence of text lines. This sequence of text lines can be (but does not have to be) a sequence of instructions. When the assembler encounters the macro label in a source code file, it replaces the macro label with the text lines that the macro label represents. This is called expanding the macro, because the name of the macro (occupying one text line) is replaced by several lines of text, which are then assembled just as though they had appeared in the source-code file all along. Macros bear some resemblance to Include files in high-level languages like Pascal. In Turbo Pascal, an include command might look like this: {$1 ENGINE.DEF} When this include command is encountered, the compiler goes out to disk and finds the file named ENGINE.DEF. It then opens the file and starts "feeding" the text contained in that file into the source-code file at the point where the include command was placed. The compiler then processes those lines as though they had always been in the source-code file. You might think of a macro as an include file that's built right into the source-code file. It's a sequence of text lines that is defined once and given a name. The Macro can then be dropped into the source code again and again by simply using the name.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.