Go to frontpage


> frontpage
> what is zine?
> download latest issue
> latest articles
> previous issues
> next issue
> contact us
> credits
> bitfellas
Using Macros

Macros are parts of your assembler-code which you need more than once in your source code. Each Macro is defined by a name. When you use a Macro you can give some parameters to it which may be different each time when you call a Makro. Not each Assembler is able to operate with Macros. For example the Devpac Assembler is able to. How to define a Macro and how to use it is different in every Assembler.

For Assembler Beginners Macros are maybe useful. But it's a tricky thing with Macros. For example you have a Macro to fill the memory with a specific Byte: (* stands for SHIFT+3)

Macro Mem(Begin,End,Byte)
lea Begin,a0
lea End,a1
move.b *Byte,d0
loop: move.b d0,(a0)+
cmp.l a0,a1
bne loop
EndMacro


When you now want to use this Macro in your source then you have to do it for example like this :

Fillmem:
Mem($20000,$30000,$FF)
...sourcecode...
Mem($60000,$75000,$00)
...sourcecode...


and so on. But I don't like Macros. The reason is simple. If you use a Macro the Assembler puts each time your Code which you defined as the Macro with the different parameters in the memory. That means for our example that the Assembler puts twice our code defined as Macro Mem in the Memory with different declaration for Begin, End, Byte. In fact for the first example it takes $20000 instead of Begin, $30000 instead of End and $ff instead of Byte.

But what can you use instead of this "useful" Macros? Good coded subroutines can do the same. But if you have time-problems then is the solution with Macros of course better. Then with Macros you have at least not to see always the same code in your source-code. But back to subroutines. If you want to jump in a multi-subroutine then you have to put your parameters in d0-d7 or/and a0-a6 or you can put them on the stack. I think that everybody has to choose his own way and decide when he likes to take Macros or create his own subroutines. I for myself prefer the way with the subroutines. And for the end an example how you could do the same with a subroutine:

Fillmem:
lea $20000,a0
lea $30000,a1
move.b *$ff,d0
bsr sub

...sourcecode...

lea $60000,a0
lea $75000,a1
moveq *$00,d0
bsr sub

...sourcecode...

sub:
move.b d0,(a0)+
cmp.l a0,a1
bne sub
rts


This is not a perfect example because the difference between Macros and subroutines isn't very big. But it's a short example. In other examples is the difference much bigger.

Com/BRS

This article originally appeared in the Amiga diskmagazine "Zine #3" by Brainstorm 1990.

Some content may refer to activities that are illegal in some countries. BitFellas does not support such activity.
Addresses and other contact information were only valid when this magazine was originally published, in february of 1990.

Go back to articlelist

Comments: (click here to comment the article)

Hosting provided by Mythic-Beasts. See the Hosting Information