Hello, new here so apologies if this has been done before and posted...
I've just started learning to use the 64Tass assembler (and brushing up on assembly language in general), and I was inspired by the wonderful article here https://wilsonminesco.com/StructureMacros/ to port some of these macros over to tass. This process has certainly helped me understand the features of Tass - I've tried to utilize the more advanced macro features where I could when porting (lists, slices, nested macros, etc.)
Posting here in case anyone finds use for these. Included a tiny bit of test/example code as well.
At some point I'll likely do more testing, as well as maybe add some more macros (for..next for sure). But I really should get back to the original point of me learning all this, and finish my emulator...
Caveat: These are all largely untested, and as I said above I'm certainly no pro at assembly nor 64Tass, so I'm sure there bugs somewhere in there.
64Tass Structural Programming Macros
-
laztrezort
- Posts: 3
- Joined: 27 Nov 2025
64Tass Structural Programming Macros
- Attachments
-
- macrotest2.asm
- (913 Bytes) Downloaded 35 times
-
- StructuralMacros2.asm
- (6.55 KiB) Downloaded 44 times
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: 64Tass Structural Programming Macros
It's nice to see others picking up on this and doing it for other assemblers! The program flow control structure macros have sure increased my productivity in, and enjoyment of, assembly language.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: 64Tass Structural Programming Macros
laztrezort wrote:
Hello, new here so apologies if this has been done before and posted...
I've just started learning to use the 64Tass assembler (and brushing up on assembly language in general), and I was inspired by the wonderful article here https://wilsonminesco.com/StructureMacros/ to port some of these macros over to tass.
I've just started learning to use the 64Tass assembler (and brushing up on assembly language in general), and I was inspired by the wonderful article here https://wilsonminesco.com/StructureMacros/ to port some of these macros over to tass.
I’m a big user of macros, to the point, in fact, where most of the mainline code in some of my programs is a series of macro invocations, with a few “raw” assembly language statements in places where macros don’t help any. As I do a lot of development for the 65C816, there tends to be a lot of activity involving stack frames and direct-page relocation, areas in which some truly awesome bugs can be created in one’s code.
However, I’ve never gotten into using macros to imitate high-level constructs, as Garth has done.
x86? We ain't got no x86. We don't NEED no stinking x86!
-
laztrezort
- Posts: 3
- Joined: 27 Nov 2025
Re: 64Tass Structural Programming Macros
GARTHWILSON wrote:
It's nice to see others picking up on this and doing it for other assemblers!
BigDumbDinosaur wrote:
For that reason, many of the macros I have written cater to “automating” such tasks (see attached for an example)
Re: 64Tass Structural Programming Macros
Hello laztrezort!
I'd recommend an alternate approach by stacking namespaces instead of branch instruction locations.
The advantage is that it's possible to define symbols like _skip or _loop in them. Using these as branch destinations there's no need for patching with .byte directives. Error diagnostics will work better, it's compatible with automatic long branching and the assembly listing becomes more readable.
I'd recommend an alternate approach by stacking namespaces instead of branch instruction locations.
The advantage is that it's possible to define symbols like _skip or _loop in them. Using these as branch destinations there's no need for patching with .byte directives. Error diagnostics will work better, it's compatible with automatic long branching and the assembly listing becomes more readable.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: 64Tass Structural Programming Macros
soci, is that .asm code for the 64Tass assembler? It'd be good if you could add some comments of explanation for those of us not familiar with that assembler. I am unfamiliar with most of those assembler directives (at least I guess that's what they are, starting with a dot).
An advantage of the structure macros is that you don't need symbols like _skip or _loop. The names of the macros, invoked in the code using them, plus indentation to set off nested structures, makes it clear what's going on. You can still of course use labels, like if you had some odd reason to jump into the middle of a structure. The structure macros just add a nice tool, without adding any constraints.
An advantage of the structure macros is that you don't need symbols like _skip or _loop. The names of the macros, invoked in the code using them, plus indentation to set off nested structures, makes it clear what's going on. You can still of course use labels, like if you had some odd reason to jump into the middle of a structure. The structure macros just add a nice tool, without adding any constraints.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
-
laztrezort
- Posts: 3
- Joined: 27 Nov 2025
Re: 64Tass Structural Programming Macros
soci wrote:
I'd recommend an alternate approach by stacking namespaces instead of branch instruction locations.
GARTHWILSON wrote:
An advantage of the structure macros is that you don't need symbols like _skip or _loop.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: 64Tass Structural Programming Macros
laztrezort wrote:
GARTHWILSON wrote:
An advantage of the structure macros is that you don't need symbols like _skip or _loop.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: 64Tass Structural Programming Macros
GARTHWILSON wrote:
soci, is that .asm code for the 64Tass assembler? It'd be good if you could add some comments of explanation for those of us not familiar with that assembler. I am unfamiliar with most of those assembler directives (at least I guess that's what they are, starting with a dot).
The .namespace/.endnamespace pair creates or uses a namespace. This allows sharing symbols across "#if" and "#else" or "#endif" for example.
The .segment/.endsegment directives are the non-scoped versions of .macro/.endmacro. I've used them because scoping would be redundant due to .namespace/.endnamespace and also if no labels are defined which need hiding.
The .function/.endfunction directives are used to implement namespace stack push/pop operations. A new empty one is added to the end (-1) or gets sliced off. Both return the top of the stack as that's what's needed to select the namespace where new labels will be defined or where the label for the branch resides.
That .switch/.case/.default/.endswitch block is a shorthand for .if/.elsif/.else/.endif and .proff/.pron hides code in listing.
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: 64Tass Structural Programming Macros
soci wrote:
That .switch/.case/.default/.endswitch block is a shorthand for .if/.elsif/.else/.endif...
Pardon me for being a gruff curmudgeon, that’s too much complication in an assembler, in my opinion.
Programming in assembly language means one is working in an inherently low-level environment that is fundamentally simple in nature. Adding pseudo-ops in an effort to make the assembler appear to be higher level doesn’t make for a better assembler, just a more complicated one.
If the purpose of adding all that .CASE .SWITCH mumbo-jumbo is to mask the low-level nature of assembly language, why not just program in a higher-level language, e.g., C? With a good compiler, C programs will run plenty fast, though not as fast as pure assembly language equivalents, but will spare the programmer from having to know about those nasty mnemonics and detailed hardware matters, such as the 65C816’s banking rules.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: 64Tass Structural Programming Macros
BigDumbDinosaur wrote:
soci wrote:
That .switch/.case/.default/.endswitch block is a shorthand for .if/.elsif/.else/.endif...
Pardon me for being a gruff curmudgeon, that’s too much complication in an assembler, in my opinion.
Programming in assembly language means one is working in an inherently low-level environment that is fundamentally simple in nature. Adding pseudo-ops in an effort to make the assembler appear to be higher level doesn’t make for a better assembler, just a more complicated one.
If the purpose of adding all that .CASE .SWITCH mumbo-jumbo is to mask the low-level nature of assembly language, why not just program in a higher-level language, e.g., C? With a good compiler, C programs will run plenty fast, though not as fast as pure assembly language equivalents, but will spare the programmer from having to know about those nasty mnemonics and detailed hardware matters, such as the 65C816’s banking rules.