Jump to content

One thing the last show didn 't make clear at all was the concept of "Macro "


G+_Lee Crocker
 Share

Recommended Posts

One thing the last show didn't make clear at all was the concept of "Macro". "MASM" is short for "Macro Assembler", a primary feature of which accounts for Steve's ability to do things like those .IF / .THEN blocks. Other assemblers do this as well.

 

Most lines of assembly code represent actual machine instructions, and are simply translated one-for-one into the machine-code of the processor. But MASM and other assemblers also have the ability to define and use macros, much like C's preprocessor. You give a name to a macro, and it expands into one or more lines of code (which might be further nested macros, or final instructions). They can take arguments, do assemble-time computations, and other things, but when they are finally invoked, they eventually end up outputting actual code.

 

For example, Steve's

 

    .IF (eax < ecx)

 

probably expands to something like

 

    cmp eax, ecx           ; compare registers

    jge    ; jump if first >= second

 

while his .THEN expands to nothing, .ELSE expands to

 

    jmp     ; skip else block

    :

 

and finally .ENDIF expands to

 

    :

 

So there's actual instructions (or labels, or nothing) being emitted, but the macros take care of things like making the label for you, figuring out which compare and jump instructions to use, etc.

 

So assembly is actually two languages: the instruction set of the processor, and instructions to the assembler itself, including its macro expansion ability.

Link to comment
Share on other sites

 Share

×
×
  • Create New...