UMBC CMSC 211

UMBC | CSEE

Pseudo-Macros for Repetition

There are three pseudo-macros which expand a prototype repeatedly:

Pseudo-Macro Meaning
REPT n REPeaT n times
IRP Indefinite RePeat
IRPC Indefinite RePeat Characters

The simplest of these is the pseudo-macro REPT which merely repeats the prototype n times. Without any parameters, we could have a macro:

  REPT 20
  DB 5, 3, ?, 18, 18
  ENDM  

This is the equivalent of:

  DB 20 DUP ( 5, 3, ?, 18, 18 )

There is a pseudo-operation that is similiar to the EQUate pseudo-op, the '=' pseudo-op. This allows the programmer to give a label a new value (which EQU can not do).

label = label + 1 ; is legal
label EQU label + 1 ; is not legal

Obviously, label must be given a value before this can happen! EQUates can be used to give symbolic names to character strings, while '=' can only be used for numeric values.

Example

We can initialize a block of memory with the lower case letters with:

Letter = 'a'
REPT 26
DB Letter
Letter = Letter + 1
ENDM

We can write a macro for a number of times, but let the computer do the counting:

IPR    parm, <x1, x2, ... xn >
...prototype containing &param&....
ENDM
  
An example is:

IRP    aReg, <ax, bx, cx, dx>
push   &aReg&
ENDM
  

This expands to:

push   ax
push   bx
push   cx
push   dx
  

Actually, we could do that one in a different manner, since there is really only one character difference:

IRPC   regLet, abcd
push   &regLet&x
ENDM
  

We can also improve the TestProg.asm program now. Where we had the 10 lines of DispNum and test numbers, we can do it as:

IRP       num, <-32768,-32767,-12345,-864,-9,-1,0,1,1057,32767>
DispNum   &num&
ENDM
  


UMBC | CSEE |