6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Tue Jul 02, 2024 1:51 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Jun 25, 2007 3:36 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
Garth seems to be the lone crusader of this technique around here, but for anyone interested, here is a link to the beginning of the manual for MacroSoft, a BASIC-like language from the halcyon days of Apple II, implemented as assembly macros (the name MacroSoft is a nod to Applesoft, the floating-point BASIC of the Apple II series).

A blurb about MacroSoft:

http://www.nibblemagazine.com/assmblr_macrosoft.htm

The manual excerpt itself:

http://www.nibblemagazine.com/macrosoft-excerpt.pdf

The excerpt at least shows some of the features and capabilities of MacroSoft and gives you an idea of the lengths to which you can go with assembler macros. Garth usually doesn't suggest anything this elaborate, though.

The classic Apple II magazine, Nibble (who also published MacroSoft) even published a few MacroSoft program listings in their magazine (which is how I knew of MacroSoft -- I never owned or used it). (Mostly, Nibble published BASIC and assembly language -- and on rare occasions, Pascal -- program listings.)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jun 25, 2007 6:59 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8462
Location: Southern California
Neat! Do you know anything about their assembler? It looks like it probably supports arrays of assember variables, ie, arrays the assembler itself uses at assembly time, not ones that go in the target computer's RAM. I'd like to do control structures with macros, and although I haven't tried to do it without an assembler-variable array to make a stack, I can imagine how to go about it, but it would get messy assuming you'd want the capability to nest these program structures. [Edit: Done. The article and source code are at http://wilsonminesco.com/StructureMacros/index.html. ]

The two 6502 assembers I've used are the 2500AD and Universal Cross-Assemblers' C32. The 2500AD allowed you to say essentially, "If there is a 3rd (or 4th, 5th, etc.) macro input parameter, do such-and-such," whereas C32 required all possible input parameters to be in the list every time you use the macro. C32 had a nice thing or two however that 2500AD could not do. I have not used the 2500AD assembler in 15 years. I have not thought of any way to jerry-rig an assembler variable array in C32, and I don't think there's any way to do it in 2500AD either.

Quote:
Garth usually doesn't suggest anything this elaborate, though.

I've had some macros where one readable line would hide a page of less-readable code, but I've only put simpler macro examples here on the forum to show the usefulness while trying to keep readers from turning glassy-eyed with special-purpose code that would be irrelevant to most people. I have not had any temptations to write a BASIC in macros, but I've bordered on putting some Forth in assembly applications.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jun 25, 2007 3:27 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
Well, Forth is just a glorified macro assembler at its core, so would that count? :-)

But, say what you will, macros can only go so far; you just can't replace a genuine high-level programming language. Compare C versus Io for example.

(For those who have never heard of Io, you can learn more at http://www.iolanguage.com)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 28, 2007 3:43 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
GARTHWILSON wrote:
Neat! Do you know anything about their assembler? It looks like it probably supports arrays of assember variables, ie, arrays the assembler itself uses at assembly time, not ones that go in the target computer's RAM. I'd like to do control structures with macros, and although I haven't tried to do it without an assembler-variable array to make a stack, I can imagine how to go about it, but it would get messy assuming you'd want the capability to nest these program structures.


I've used a few different Apple II assemblers, but not that one, so I'm not really all that familiar with it. I've seen source listings of programs written for that assembler published in magazine articles, and from that, I know it has a lot in common with other popular Apple II assemblers of the day. But that's the same way it is here in the forum and repository; it doesn't really matter what assembler the source code was written for, because even though they may differ somewhat in terms of strengths and capabilities, they really aren't all that different from each other. Most of the (albeit intentionally general syntax-wise) source code in the forum and repository can be assembled on just about anything, it's mainly a process of converting syntax like DB to .BYTE, or vice versa.

Anyway, I may be overlooking something, but I'm thinking control structures can be implemented with just ordinary labels. One very simplistic way is to always put a label at the destination that an IF/WHILE/whatever would branch to, for example:

Code:
LOOP1: DO
LOOP2: DO
       ...
       WHILE (VAR2 < 10), LOOP2
       WHILE (VAR1 < 10), LOOP1


Obviously, this isn't as convenient as omitting the labels would be, but if the goal isn't to implement an elegant high level langauge, but rather to provide some not-as-low-level-as-assembly constructs (even if the level is only a teensy bit higher than assembly), then this might at least provide an incremental improvement.

Another possibility is that there are/were assemblers that took special action when certain characters were found in a label. For example, @ might be the name of a special variable; if the character @ were found in a label it would substitute the value of the variable @ at that point in the label; for example:

Code:
@       = 8
        .STARTLOOP 4  ; loop 4 times
DELAY@: NOP
@       = @-2
        .ENDLOOP


would be equivalent of:

Code:
DELAY8: NOP
DELAY6: NOP
DELAY4: NOP
DELAY2: NOP


Or @ could be used in macros to generate unique global labels (which could then be referenced outside the macro) each time the macro was invoked. (I should point out, though, that this specific @ behavior isn't taken from any particular assembler.)

Anyway, using @ inside macros for DO and WHILE would allow:

Code:
DO
VAR2 = 1
DO
; ...
WHILE (VAR2 < 10)
WHILE (VAR1 < 10)


to generate:

Code:
LABEL1: LDA #1
        STA VAR2
LABEL2:
; ...
        LDA VAR2
        CMP #10
        BCC LABEL2
        LDA VAR1
        CMP #10
        BCC LABEL1


by incrementing and decrementing @ in the DO and WHILE macros.

Anyway, the above is pretty much just off the top of my head; I haven't actually tried any of it.

GARTHWILSON wrote:
I have not had any temptations to write a BASIC in macros, but I've bordered on putting some Forth in assembly applications.


In the case of MacroSoft, I would think it was more of attempt to capitialize on the popularity of BASIC, while providing increased performance, rather than attempt to seek out (or develop) a highly suitable and elegant high level language to implement via assembler macros. Had a different language been built into the Apple II, MacroSoft may well have went that direction. As it was, in those days, there were a lot of products oriented toward improving BASIC performance; there was definitely a market for that sort of thing then.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 09, 2007 3:58 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
I decided to add a simple structured programming feature to my portable assembler. It now does if/else/endif, repeat/until and while/endw based on condition register flags.
Code:
                                     .65C02
                           
                            ; A mixture of loops and ifs
                           
000899' A000              :         LDY #0
00089B'                   :         REPEAT
00089B' 98                :          TYA
00089C' A200              :          LDX #0
00089E'                   :          REPEAT
00089E' 0A                :           ASL A
00089F' 08                :           PHP
0008A0' 9001              :           IF CS
0008A2' E8                :            INX
0008A3'                   :           ENDIF
0008A3' 28                :           PLP
0008A4' D0F8              :          UNTIL EQ
0008A6' C8                :          INY
0008A7' C080              :          CPY #128
0008A9' D002              :          IF EQ
0008AB' 8002              :           BREAK
0008AD'                   :          ENDIF
0008AD' 80EC              :         FOREVER
                                   
                            ; Nonsense code to show long branches
                           
                                    .ORG $E000

00E000  90034C09E1        :         WHILE CC
                                     .REPEAT 16
                                     .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
                                     .ENDR
00E005  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E015  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E025  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E035  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E045  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E055  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E065  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E075  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E085  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E095  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E0A5  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E0B5  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E0C5  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E0D5  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E0E5  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E0F5  EAEAEAEAEAEAEAEA> +          .BYTE $EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA
00E105  0A                :          ASL A
00E106  4C00E0            :         ENDW

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: