Jump to content
Multijointed Monster Maker

Macros (I wish I new about them sooner on)

Recommended Posts

For you other programmers on this website, how long did it take you before you found out what a macro was? I've been programming over a year, and gotten almost nowhere, until I learned how to use macros. Now I'm using almost all my code is macros and it's taking me far less time to program.

Share this post


Link to post
Share on other sites

I found out quite quickly.

 

I was programming Z80 at the time and wrote a macro to add an offset to the contents of HL register pair, as I remember. Sort of indirect indexing.

 

However my epiphany was the "linker". This allows me to write and build subroutines and libraries of code then reuse the code later as a binary (no need to reassemble)

 

Oh yes and "makefiles" really cool stuff.

 

It was 20, and some, years ago now :sad:

Share this post


Link to post
Share on other sites

A quarter of a century writing 6502 and i've never used macros.

Share this post


Link to post
Share on other sites

A quarter of a century writing 6502 and i've never used macros.

 

What systems have you programmed before? I find Super Nintendo to be very tedious to program without using macros.

 

Code released for VIC 20, C64, Plus/4, PET, C64DTV and Atari 8-bit series, almost complete code on Atari 2600 and NES and some experimentation on the BBC Micro and a couple of others.

Share this post


Link to post
Share on other sites

I don't use them a great deal.

 

They can potentially lead to lazy, unnecessarily bloated code.

Share this post


Link to post
Share on other sites

I love macros :) But not to the point that some people use them that makes code unreadable. I don't use them much on 8bit stuff because it's unlikely I'll be doing big swathes of repeated code. I say keep them simple just to save repetitive typing and make source code easier to read. Some people go insane and have crazy formulaic ones and you have no clue looking at the code that calls the macro wtf is supposed to be happening.

 

 

Pete

Share this post


Link to post
Share on other sites

I love using macros in an editor but not so much for coding.

The more advance the CPU the less you have to gain from macros.

They would be much more useful on a 6502 than a 68000 for example.

A small number of special purpose registers and the need for a lot of repeated functions (16 bit add for example) makes the 6502 a very good target for macros.

But you don't need a macro to do the same thing on a 68000... or even a 6809 or 6803.

 

The use of macros *can* leave to bloated code if you over use them because they tend to be general purpose and a routine directly targeted at a specific piece of code may not require all the instructions in a macro. But that does not have to be the case.

 

 

There are several reasons *I* avoid using macros.

 

Macro support from one assembler to the next varies a lot and I usually have to switch assemblers based on a project.

I don't get to choose the tools I have to use at work.

 

I haven't been doing enough hobby stuff on any one machine to really get used to the quirks of a specific assembler.

 

It usually takes longer to write a good macro than to cut an paste an existing piece of code.

 

Code is usually easier to follow without macros.

 

There are some govt standards that don't allow their use.

It's better for me that I don't get in the habit of using them.

 

 

But then there are some projects where they want you to use macros or templates.

Templates don't really apply to assembly but they a really good example of just how powerful macros can be.

Share this post


Link to post
Share on other sites

I mainly use them for generating data tables. In my mind it makes the code look neater. It also means that if you change something in the table, reorder it or add an element its much easier to make changes.

Share this post


Link to post
Share on other sites

The more I get used to assembly the less I use them. But there are just cases where they are really useful. Like a sleep macro, or the macros that insert code for handling the tv synchronisation signals (2600 stuff).

Share this post


Link to post
Share on other sites

I dont make use of them and really did not use them until the Jag risc chips. There are a

few reasons why I used them. One was to make a psuedo JSR and RTS instruction, which I dont

use anymore and the only ones I actually use now are simply to make padding GPU main RAM

code modules between code pages look neater. Outside of this though, there is no real good

use for them that I have found. Your mileage may vary.

Edited by Gorf

Share this post


Link to post
Share on other sites

I'm with GroovyBee/roland p; I use them in a limited fashion for some data tables and for a very few other things (SLEEP, CLEAN_START).

 

I think too many macros makes the code very difficult to read; for the 2600, also, where you frequently need to optimize and rearrange data at a byte level, macros are too blunt.

Share this post


Link to post
Share on other sites

I'm with GroovyBee/roland p; I use them in a limited fashion for some data tables and for a very few other things (SLEEP, CLEAN_START).

 

I think too many macros makes the code very difficult to read; for the 2600, also, where you frequently need to optimize and rearrange data at a byte level, macros are too blunt.

 

I'll chime in in this direction also. I mainly use macros for data tables and other data-related stuff. I rarely (but not never) use them for code. Macros hide too much of what the code is doing, which can lead to inefficiency or strange surprises. They do make sense in a few places to eliminate some tedium, but only a few.

 

For data, they insulate the data encoding from what's being encoded, allowing you to quickly change the encoding if necessary. When I wrote Space Patrol, I ended up re-encoding several data structures multiple times until I got things the way I wanted them. Because I hid the encoding behind a macro, I just had to update the affected macros. The data tables stayed put.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...