Is this a macro1 bug?

41 views
Skip to first unread message

Bill E

unread,
Nov 16, 2025, 7:35:26 AMNov 16
to [PiDP-1]
This has hit me several times. Macro1 will treat anything after a / as a comment, so something like
100/ jmp x
completely fails. However, the original macro manual shows this as perfectly valid.
Or, is this one of those dang invisible tab-vs-space things?
Again, the macro manual shows space or tab working, see page 8, location assignment.
This was done with a space between the / and the jmp:

      Check behavior of /                                                 Page 1


    1                   Check behavior of /
    2 00100             100/ jmp .
      00100 000100
    3 00101 600101          jmp .
    4 00110             110/ jmp .
      00110 000110
    5                  
    6       000100      start 100

      No errors detected

If I replace the space with a tab, the proper code is generated. I haven't tried this with macro, I never use it. Well, I did once just so I could say I did, but doing real development is far too tedious with it.

Bill

Norbert Landsteiner

unread,
Nov 16, 2025, 8:20:51 PMNov 16
to [PiDP-1]
You are correct, according to the examples in the Macro manual, this should be possible.
There are actually several examples in the Manual illustrating this in various ways.

Also, the Macro Internal Operation Manual describes:

> LOCATION ASSIGNMENTS
> The location assignment character </> enters at b. If preceded by a word terminator, it denotes the beginning of a comment, and control passes to itc to ignore characters until the next tab or carriage return. Otherwise, evl is called and the new location is set up.

So, according to this, if the slash was not preceded by a word terminator (see below), the expression before this should be evaluated and the result used as the new location.
If, on the other hand, it was preceded by a word terminator, i.e., is at the beginning of a logical input line, it's a comment.

Consequently, the slash is found itself in the list of word terminators:

> Expressions are usually delimited by tab, cr, slash, comma, or equals.

BTW, valid syllable separators, which are conjunction of factors in an expressions, are.

> an expression is one or more syllables separated by the characters plus, minus, or space.

So much, so clear.
However, this is not how it behaves. Clearly, we can separate a comment from any expression / instruction just by spaces (and, actually, as demonstrated in your example, even by no separation, at all.) While, according to the above, in this case, the instruction code should be used as the new location, since space is a syllable terminator and not a word terminator.

This actual behavior is also supported by section on comments:

> Comments - A string of characters which commences with a slash is a comment. The string is ended by a tab or cr.
Comments are ignored by MACRO and may be used to label selections of a program, annotate important instructions, and give the reader of the typescript information about the program.

Notably,  there is no requirement for the slash to be proceeded by any special / terminating character to start a comment.
From which follows that a location expression must be terminated (either by a CR or TAB), in order to not be parsed as some literal value expression followed by a comment.

Obviously, there is a contradiction.
My guess is that the behavior described in the context of location setting may have been the original one, as drafted, and later revised, but this was not fully reflected in the manual.
And I can kind of see, why this should have been revised, since, if the slash did actually behave as described above and we had to put any comments exactly on the start of a new line and nowhere else, this shouldn't be only quite awkward, but also extremely error-prone, as in accidentally setting a new location, if any character happened to precede the slash.

The other version is that the slash fails to act as a word terminator (as described). (Still, we would have to put any comments at the very beginning of a line. Which makes me presume that the demonstrated behavior is intentional. Also, this double-identity of the slash is awkward per-se and may be somehow owed to the previous TX-0 incarnation.)

Anyways, for the sake of having functional comments, terminate the location expression.

Best,
Norbert

Norbert Landsteiner

unread,
Nov 17, 2025, 3:52:34 AMNov 17
to [PiDP-1]
Thinking of it, it could well be that Macro actually behaves as described and Macro1.c deviates in this instance from a faithful port.
(I never investigated the original Macro regarding this.)
If so, I can totally see why Macro1.c would do so, especially, since there are several modern formats that don't go well together with tabs, like e-mail.

If this is the actual behavior of Macro and given that a space is a legitimate part of an expression, this may yield some unintended and frankly quite horrible results:

y,  100     /y-coor
=>
y,[TAB]100[SPACE][SPACE][SPACE][SPACE][SPACE]/y-coor
=>
"y",[TAB]"100     "/"y-coor"
=>
<label-string><label-terminator><terminator><expression><slash = terminator>...
=>
<label><terminator><address><set_location>...
=>
y,
100/
y-coor
=>
:define symbol "y" as current location
:set current location to 100
:insert value of expression "y-coor" (at loc. 100) and increment location

("y-coor" will probably resolve to the address of label "y" less the default value 777777 for the undefined symbol "coo", i.e., "y-(-0)" => y.)
This is just awful!


Best,
Norbert

Bill E

unread,
Nov 17, 2025, 2:01:25 PMNov 17
to [PiDP-1]
Interesting. A disadvantage of ad-hoc parsing. This is easy to handle with lex/yacc which have been around since 1971 or so,, or even a pretty simple crafted LR recursive descent parser. Of course, that was not an option for macro, but no excuse for macro1, imho. Hmm, now where's my compiler bible, aka The Dragon Book?
Bill

Norbert Landsteiner

unread,
Nov 17, 2025, 3:47:58 PMNov 17
to [PiDP-1]
I think, this is really a problem with the grammar as described in the Macro manual, i.e., the slash not only terminating the word before it, but also terminating after itself, unless it is (as defined implicitly) at the very start of a logical input line. This just invites disaster with modern editing devices (probably not so much, back in the day.)
I personally think, the behavior exhibited by 'macro1.c' is really the way to go. I.e., to be a location directive, a slash must follow an expression AND must be explicitly terminated. I'd recommend to implement it this way in any modern assembler, since this should be so mach safer.
I'd be also ok and comfortable with an explicit assignment to the location symbol (like in some other assemblers), as in ". = 100", which fits the rest of the grammar pretty well.

(Similarly, any amount of white space following a comma, which terminates a label, should amount to the equivalent of a tab. There's no ambiguity in this, but it gets rid of the ambiguity of a run of spaces and a tab, almost entirely. This leaves the peculiar use of tab only for multiple instructions chained on a single line, but this should be (a) be discerned easily, and (b) be edited to multiple lines pretty easily without any change of meaning, since tab and CR are equivalent.)

Best,
Norbert

Norbert Landsteiner

unread,
Nov 17, 2025, 4:25:21 PMNov 17
to [PiDP-1]
BTW, there's some behavior of Macro (and also shown by macro1.c), which is in contradiction to the manual.
Namely, the construct used by Steve Russell for his constants table at the start of Spacewar:

/ interesting and often changed constants

/symb loc   usual value (all instructions are executed,
            / and may be replaced by jda or jsp)

tno, 6,     law i 41    / number of torps + 1
tvl, 7,     sar 4s      / torpedo velocity
...

So, what are "6", "7", etc., following the labels? Clearly, these are meant to annotate the memory locations, where these go, but: how does this fit the grammar?
The only interpretation, I can come up with, is that these are parsed as labels (they are followed by commas), but the Macro manual also states that a symbol is any amount of 1 to 3 characters (since 3 characters fit into a word) of figures and/or letters, of which at least one has to be a letter (which isn't the case).
It's rather intuitive that we're not allowed to redefined a basic symbol like a figure, but how does this not trigger an error?
(I'm probably missing some, here. Or is this actually redefining "6" by the value of the current location, which happens to be 6? Anyways, Steve Russell is showing off here quit a bit…)

Best,
Norbert
Reply all
Reply to author
Forward
0 new messages