outofmbufs / python-pdp11-assembler

PDP-11 unix v7 syntax assembler, in python
MIT License
3 stars 0 forks source link

Left shift and Right shift in unix7 as #2

Closed outofmbufs closed 1 month ago

outofmbufs commented 1 month ago

While testing scenarios for the string-parsing bug (see https://github.com/outofmbufs/python-pdp11-assembler/issues/1) I was writing some test code for left-shift (<\<) and right-shift and discovered that THEY don't work at all in native unix7 as:

image

... so I guess it's up to me to make them work the way the manual says, but there's a bug in the assembler itself in the unixv7 distro (the above test was run under simh) so there's no way to verify correct semantics.

Did a 'find' on the entire /usr/src tree in unixv7 and there seem to be (unsurprisingly) no instances of a .s file that use left-shift or right-shift in any expressions (this is not about the instructions, this is about FOO = 1 + 3 kinds of things but using left-shift or right-shift in the expression).

outofmbufs commented 1 month ago

After more poking around and thought ... note that the 'g' error ("g 0001", twice, in the post above) means (per the man page and the "Unix Assembler Reference Manual") "garbage character" so the '>>' became two garbage characters. And in line two the '<' error means "string not terminated properly" though the manual says that should a '>' error.

There's a lot of ambiguity in lexing here, so my guess is that << and >> were just never implemented (and, as noted above, are never used in the unix v7 sources). So ... the fix for this bug is going to be: taking out << and >> entirely. :)

outofmbufs commented 1 month ago

Fixed w/ https://github.com/outofmbufs/python-pdp11-assembler/commit/89222be39c68811ad8a1da042e0ef1655812dea8

outofmbufs commented 1 month ago

After studying the source of v7 'as', discovered that the left/right shift expression operators ARE implemented, but they use this syntax: foo = 1 \< 3 bar = 0377 > 6 mov $foo, r0 mov $bar, r1

which results in this (running v7 under SIMH):

image

Note that the backslash is essential, otherwise '<' by itself starts a string and '>' by itself triggers a 'g' ("garbage character") error.

This is not documented -- neither the "Unix Assembler Reference Manual" (which lists the operators as << and >>) nor the 'as' man page shows this form.

outofmbufs commented 1 month ago

Just one more FYI comment - Running v7 under simh I did a find/grep for any .s file using < or > for left/right shift in an expression and found only this one example in /usr/sys/40/m40.s (the startup code for the kernel on an 11/40):

mov $usize-1\<8|6,(r1)+

It is setting up ksr6 / _u mapping. So the construct definitely gets used, but this appears to be the ONLY place (and note that it uses the \< as discussed, not <<).

The 11/45 11/70 startup code is entirely different and does not use this construct.