WheelInventor wrote:
Garth, welcome and thanks for moderating 6502.org, that side is a great learning resource. Using BASIC-like structure macros would help me a lot.
I patterned mine mostly off of standard Forth structures, with a notable exception being FOR...NEXT, because I didn't think the Forth way,
<to> <from> DO...LOOP
would be as easy to pick up for people who have not been using Forth. (It's like a gift with the tag on it, "To: <recipient> From: <giver>.)
Quote:
Here's a newbie question: Is replacing BRA with a known condition in your macro files as "straightforward" as it would be when writing in plain assembly? I guess my question is; can the condition always be known in a general macro?
I'm not sure exactly what you're asking, so I'll try to answer a few different possibilities.
Yes, you can still use labels and normal branch instructions at any time, like if you don't have a structure macro yet to do exactly what you want. In most cases, it will be good discipline to try to stick with a good set of structures (which may mean you change the way you approach the problem); but there is no denying that once in a while you'll have a situation where you will get better efficiency if you can branch into the middle of one for example, using a label.
Another thing I can imagine you might mean is about BRA versus JMP, like if the structure is so long that B__ won't reach. I find that those situations are rare, so the macros I provide on that section of my website don't provide for them. (Again, you can use the old way at any time, if you need to.) I do use JMP for the END_OF's in a CASE structure where after executing the conditional code, you jump to the end of the structure which, with many cases involved may well be too far for a mere branch. (I also provide END_OF_ (with the trailing "_") to mean not to assemble anything right there for situations where you end the case with RTS for example, or follow it with END_CASE so there's no point in jumping to what comes next anyway.
I do use the CMOS 65c02 instructions, including BRA, in the macros I provide. You can easily replace BRA with JMP for your own use if you're using an NMOS 6502 that doesn't have those instructions. If you re-write them for the 65816, you can use BRL too, "Branch Relative Long," which uses a 16-bit offset suitable for relocatable code. The structure macro thing is not that difficult to understand, but it sure is hard to explain clearly. If the reader catches on, he will be able to make whatever new ones he wants. If you know what's in the macros, whether you use mine or write your own, you will know exactly what code gets laid down. The benefit of course is that you become more productive, get fewer bugs, better code maintainability, etc., and in most cases, there will be absolutely zero penalty in memory taken or in execution speed, because it's producing the same code you would do by hand anyway—it's just that you don't have to look at the ugly internal details every time anymore.
Andrew Jacobs' As65 assembler has the program-structure capability built in, and he has made it so it automatically uses JMP if a branch instruction won't reach. Again, the need is rare.