answersLogoWhite

0


Best Answer

Macros and procedures

Procedure

Definition of procedure

A procedure is a collection of instructions to which we can direct the flow of our program, and once the execution of these instructions is over control is given back to the next line to process of the code which called on the procedure.

Procedures help us to create legible and easy to modify programs.

At the time of invoking a procedure the address of the next instruction of the program is kept on the stack so that, once the flow of the program has been transferred and the procedure is done, one can return to the next line

of the original program, the one which called the procedure.

Syntax of a Procedure

There are two types of procedures, the intrasegments, which are found on the same segment of instructions, and the inter-segments which can be stored on different memory segments.

When the intrasegment procedures are used, the value of IP is stored on the stack and when the intrasegments are used the value of CS:IP is stored.

To divert the flow of a procedure (calling it), the following directive is used:

CALL NameOfTheProcedure

The part which make a procedure are:

Declaration of the procedure

Code of the procedure

Return directive

Termination of the 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

On the declaration the first word, Adding, corresponds to the name of out

procedure, Proc declares it as such and the word Near indicates to the MASM

that the procedure is intrasegment.

The Ret directive loads the IP address stored on the stack to return to the original program, lastly, the Add Endp directive indicates the end of the procedure.

To declare an inter segment procedure we substitute the word Near for the

word FAR.

The calling of this procedure is done the following way:

Call Adding

Macros offer a greater flexibility in programming compared to the

procedures, nonetheless, these last ones will still be used.

Macros

Definition of the macro

A macro is a gro 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 TASM - 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.

TOP

Syntax of a Macro

The parts which make a macro are:

Declaration of the macro

Code of the macro

Macro termination directive

The declaration of the macro is done the following way:

NameMacro MACRO [parameter1, parameter2...]

Even though we have the functionality of the parameters it is possible to

create a macro which does not need them.

The directive for the termination of the macro is: ENDM

An example of a macro, to place the cursor on a determined position on the

screen is:

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

To use a macro it is only necessary to call it by its name, as if it were

another assembler instruction, since directives are no longer necessary as

in the case of the procedures. Example:

Position 8, 6

Macro Libraries

One of the facilities that the use of macros offers is the creation of

libraries, which are groups of macros which can be included in a program

from a different file.

The creation of these libraries is very simple, we only have to write a

file with all the macros which will be needed and save it as a text file.

To call these macros it is only necessary to use the following instruction

Include NameOfTheFile, on the part of our program where we would normally

write the macros, this is, at the beginning of our program, before the

declaration of the memory model.

The macros file was saved with the name of MACROS.TXT, the

instruction Include would be used the following way:

;Beginning of the program

Include MACROS.TXT

.MODEL SMALL

.DATA

;The data goes here

.CODE

Beginning:

;The code of the program is inserted here

.STACK

;The stack is defined

End beginning

;Our program ends

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between macros and procedures in assembly language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between assembly and sub-assembly?

== ==


What is the difference between customer service standard's policies and procedures?

Difference between Customer Service Standards and Policies and Procedures


What is the difference between the un general assembly and the un security council?

difference between general assembly and security council


What is the difference between the indexing and coding filing procedures?

the difference between coding and filling


WHAT IS THE DIFFERENCE BETWEEN LANGUAGE AND COMMUNICATION I NEED RARE ANSWERS ONLY?

what is the difference between speech,language and communication??There is a huge difference between language and communication


What is one difference between the assembly and council of 500 in Athens?

The assembly was large


Difference between HTML and assembly language?

HTML : Hypertext Markup Language is a scripting language used to write websites. Assembly language is a programming language (aka ASM). It uses memory registers like EAX, ECX to hold values and commands like JMP, ADD, MOV to alter those values. Assembly language is very close to machine language and very abstract to the untrained eye. In short, they are nothing a like, and share no similarities.


What is the difference between language and culture?

Language refers to the system of communication using words and rules for their use, while culture encompasses the beliefs, customs, and traditions of a group of people. Language is a key component of culture as it reflects and shapes cultural identity and values. Language is one aspect of culture, alongside other elements such as art, music, religion, and social behaviors.


State the differences between machine language and assembly language?

Assembly language is a readable way of representing machine language. It consists of mnemonics that can be directly converted to machine language. Assembly language allows easier jump instructions with the usage of labels which gets converted to real addresses after assembling.


What is the difference between rules and procedures?

the difference is that Rules are for undesirable behaviors that have set consequences while procedures are expected classroom behaviors with no set consequences for a violation.


What is the difference between production and assembly?

CTE for life n!%%a


What is difference between assembly and installation?

James Taylor is a gimp