Macro Assembler

Macro assembler is an assembly language that allows macros to be defined and used. The Microsoft Macro Assembler (MASM) is an x86 assembler that uses the Intel syntax for MS-DOS and Microsoft Windows.

It translates a program written in macro language into the machine language. A macro language is the one in which all the instruction sequence can be defined in macro block. A macro is an instruction sequence that appears repeatedly in the program assigned with specific name. The MASM replaces a macro name with appropriate instruction sequence whenever it encounters a macro name. E.g.

Initiz macro
    Mov ax, @dataseg
    Mov ds, ax
    Mov es, ax 
Endm

OR, Initiz { Mov ax, @dataseg
Mov ds, ax
Mov es, ax }

There exists little difference between macro program and subroutine program.

When a subroutine program occurs in program, execution jumps out of main program and executes subroutine and control returns to the main program after RET instruction. A macro, in the other hand, does not cause program execution to branch out of main program. Each time a macro occurs, it is replaced with appropriate sequence in the main program.

Advantages of using Macro
  • To simplify and reduce the repetitive coding.
  • To reduce errors caused by repetitive coding.
  • To make assembly language program more readable.

No comments:

Post a Comment