I've been writing some stand alone (no OS) MACRO-11 code lately, that
has some sections that need longword alignment.
Word alignment would be easy....a .EVEN directive would take care of
it. But there's no .LONG in MACRO-11.
I reckon I can do some location counter arithmetic to get it done,
but I'm wondering if there's already a known solution for this.
-a I've been writing some stand alone (no OS) MACRO-11 code lately, that has some sections-a that need longword alignment.
-a Word alignment would be easy....a .EVEN directive would take care of
it. But there's no .LONG in MACRO-11.
-a I reckon I can do some location counter arithmetic to get it done,
but I'm wondering if there's already a known solution for this.
On 2022-01-14 17:18, Lee Gleason wrote:
And while it's pretty straight forward in theory, I can't create such a padding in MACRO-11. The problem is that I'm not allowed to do that kind
of arithmetic on the current location, as it is a relative value.
But maybe I'm just not creative enough right at this moment.
But with that said, I do have a MACRO-11 definition of .LONG which works just fine. :-)
-a Johnny
On 1/14/2022 11:23 AM, Johnny Billquist wrote:
On 2022-01-14 17:18, Lee Gleason wrote:
And while it's pretty straight forward in theory, I can't create such a
padding in MACRO-11. The problem is that I'm not allowed to do that kind of >> arithmetic on the current location, as it is a relative value.
But maybe I'm just not creative enough right at this moment.
But with that said, I do have a MACRO-11 definition of .LONG which works just
fine. :-)
-a-a Johnny
FYI I made up this macro for MACRO-11 that aligns the current location counter
such that the 'arg1' low bits are zeroes.
'arg1' can be 1 for word, 2 for longword, 3 for quadword, etc.
HOWEVER the alignment is relative to the start of the current
program/data section, which the linker normally only word aligns. So I
only use it in absolute sections where I can set the starting address to
0, 1000(8), etc.
.macro-a-a-a align-a-a-a arg1
.nlist
-a-a-a-a$$pos=1
.rept-a-a-a arg1
.if ne <.&$$pos>
-a-a-a-a.blkb-a-a-a $$pos
.endc
-a-a-a-a$$pos=$$pos*2
.endr
.list
.endm-a-a-a align
If your assembler has an 'insert string' directive which takes
parameters, it's fairly simple, something like:
DS length,fillbyte DS (($+3) BINARYAND -4)-$, 0
to align to a multiple of 4, as a general case of:
DS (($+num-1) BINARYAND -num)-$,0
where num is a power of two and $ is the location counter.
On Sun, 16 Jan 2022 10:11:12 -0800, Jonathan Harston wrote:
DS (($+num-1) BINARYAND -num)-$,0
where num is a power of two and $ is the location counter.Pretty sure I used to use someting like:
.=(.+3)&4
On Sunday, 16 January 2022 at 21:46:30 UTC, Bob Eager wrote:
On Sun, 16 Jan 2022 10:11:12 -0800, Jonathan Harston wrote:
DS (($+num-1) BINARYAND -num)-$,0Pretty sure I used to use someting like:
where num is a power of two and $ is the location counter.
.=(.+3)&4
What does that do to the memory between current . and new . ?
On Sunday, 16 January 2022 at 21:46:30 UTC, Bob Eager wrote:
On Sun, 16 Jan 2022 10:11:12 -0800, Jonathan Harston wrote:
DS (($+num-1) BINARYAND -num)-$,0Pretty sure I used to use someting like:
where num is a power of two and $ is the location counter.
.=(.+3)&4
What does that do to the memory between current . and new . ?
In may assemblers I found it was unassigned, so I used an explicit memory-filling directive, particularly after somebody pointed out
the random unassigned locations made binary diffs fiddlier as you
would almost always get differences reported.
In the PDP11 assembler wot i rote I implemented (and, importantly, documented) an ALIGN directive as explicitly filling with zeros.
On 2022-01-16 15:03, Jonathan Harston wrote:
On Sunday, 16 January 2022 at 21:46:30 UTC, Bob Eager wrote:
On Sun, 16 Jan 2022 10:11:12 -0800, Jonathan Harston wrote:
DS (($+num-1) BINARYAND -num)-$,0Pretty sure I used to use someting like:
where num is a power of two and $ is the location counter.
.=(.+3)&4
What does that do to the memory between current . and new . ?
In may assemblers I found it was unassigned, so I used an explicit
memory-filling directive, particularly after somebody pointed out the
random unassigned locations made binary diffs fiddlier as you would
almost always get differences reported.
In the PDP11 assembler wot i rote I implemented (and, importantly,
documented) an ALIGN directive as explicitly filling with zeros.
I think you meant to write: .=(.+3)&(-4)
as your expression only generates the values of 0 or 4 for the new '.'.
On 1/14/2022 11:23 AM, Johnny Billquist wrote:
On 2022-01-14 17:18, Lee Gleason wrote:
And while it's pretty straight forward in theory, I can't create such
a padding in MACRO-11. The problem is that I'm not allowed to do that
kind of arithmetic on the current location, as it is a relative value.
But maybe I'm just not creative enough right at this moment.
But with that said, I do have a MACRO-11 definition of .LONG which
works just fine. :-)
-a-a Johnny
-aCare to share it?
On 2022-01-14 12:55, Lee Gleason wrote:
On 1/14/2022 11:23 AM, Johnny Billquist wrote:
On 2022-01-14 17:18, Lee Gleason wrote:
And while it's pretty straight forward in theory, I can't create such
a padding in MACRO-11. The problem is that I'm not allowed to do that
kind of arithmetic on the current location, as it is a relative value.
But maybe I'm just not creative enough right at this moment.
But with that said, I do have a MACRO-11 definition of .LONG which
works just fine. :-)
-a-a Johnny
FYI I made up this macro for MACRO-11 that aligns the current location counter
such that the 'arg1' low bits are zeroes.
'arg1' can be 1 for word, 2 for longword, 3 for quadword, etc.
HOWEVER the alignment is relative to the start of the current
program/data section, which the linker normally only word aligns. So I
only use it in absolute sections where I can set the starting address to
0, 1000(8), etc.
.macro-a-a-a align-a-a-a arg1
.nlist
-a-a-a-a$$pos=1
.rept-a-a-a arg1
.if ne <.&$$pos>
-a-a-a-a.blkb-a-a-a $$pos
.endc
-a-a-a-a$$pos=$$pos*2
.endr
.list
.endm-a-a-a align
If your assembler has an 'insert string' directive which takes
parameters, it's fairly simple, something like:
DS length,fillbyte
DS (($+3) BINARYAND -4)-$, 0
to align to a multiple of 4, as a general case of:
DS (($+num-1) BINARYAND -num)-$,0
where num is a power of two and $ is the location counter.
On 2022-01-16 15:03, Jonathan Harston wrote:
On Sunday, 16 January 2022 at 21:46:30 UTC, Bob Eager wrote:
On Sun, 16 Jan 2022 10:11:12 -0800, Jonathan Harston wrote:
DS (($+num-1) BINARYAND -num)-$,0Pretty sure I used to use someting like:
where num is a power of two and $ is the location counter.
.=(.+3)&4
What does that do to the memory between current . and new . ?
In may assemblers I found it was unassigned, so I used an explicit
memory-filling directive, particularly after somebody pointed out
the random unassigned locations made binary diffs fiddlier as you
would almost always get differences reported.
In the PDP11 assembler wot i rote I implemented (and, importantly,
documented) an ALIGN directive as explicitly filling with zeros.
I think you meant to write:-a-a .=(.+3)&(-4)
as your expression only generates the values of 0 or 4 for the new '.'.
As to the fill for unused locations, the PDP-11 linker won't place
anything in the unreferenced locations and won't refer to them.
So any binary difference checker on generated object or load files
should still compare. Once you load the program into actual memory
of course whatever exists there will stay there, unchanged.
On 2022-01-17 02:41, Don North wrote:
On 2022-01-16 15:03, Jonathan Harston wrote:
On Sunday, 16 January 2022 at 21:46:30 UTC, Bob Eager wrote:
On Sun, 16 Jan 2022 10:11:12 -0800, Jonathan Harston wrote:
DS (($+num-1) BINARYAND -num)-$,0Pretty sure I used to use someting like:
where num is a power of two and $ is the location counter.
.=(.+3)&4
Yeah. Don just got it slightly wrong. :-)
But I would have written it as:
. = (. + 3) & ^C3
(Where ^C means ones complement in Macro-11.)
On 2022-01-16 19:11, Jonathan Harston wrote:
If your assembler has an 'insert string' directive which takes
parameters, it's fairly simple, something like:
DS length,fillbyte
DS (($+3) BINARYAND -4)-$, 0
to align to a multiple of 4, as a general case of:
DS (($+num-1) BINARYAND -num)-$,0
where num is a power of two and $ is the location counter.
Yes, except that in Macro-11, the location counter in a normal section is relative, and thus you are not allowed to do an AND on it. :-(
Which in a sense makes sense, since the code you are doing might be placed on
any location by the linker, thus making your computation for an aligned address
at assembler time to not be correct at all.
-a Johnny
On 2022-01-17 09:56, Johnny Billquist wrote:
On 2022-01-17 02:41, Don North wrote:
On 2022-01-16 15:03, Jonathan Harston wrote:
On Sunday, 16 January 2022 at 21:46:30 UTC, Bob Eager wrote:
On Sun, 16 Jan 2022 10:11:12 -0800, Jonathan Harston wrote:
DS (($+num-1) BINARYAND -num)-$,0Pretty sure I used to use someting like:
where num is a power of two and $ is the location counter.
.=(.+3)&4
Yeah. Don just got it slightly wrong. :-)
But I would have written it as:
. = (. + 3) & ^C3
(Where ^C means ones complement in Macro-11.)
Well actually we both got it ~slightly~ wrong ... the correct syntax:
-a . = <. + 3> & ^C3
which as pointed out ONLY works in absolute PSECTs.
Throws an error in relative PSECTs.
On 2022-01-18 01:17, Don North wrote:
On 2022-01-17 09:56, Johnny Billquist wrote:
On 2022-01-17 02:41, Don North wrote:
On 2022-01-16 15:03, Jonathan Harston wrote:
On Sunday, 16 January 2022 at 21:46:30 UTC, Bob Eager wrote:
On Sun, 16 Jan 2022 10:11:12 -0800, Jonathan Harston wrote:
DS (($+num-1) BINARYAND -num)-$,0Pretty sure I used to use someting like:
where num is a power of two and $ is the location counter.
.=(.+3)&4
Yeah. Don just got it slightly wrong. :-)
But I would have written it as:
. = (. + 3) & ^C3
(Where ^C means ones complement in Macro-11.)
Well actually we both got it ~slightly~ wrong ... the correct syntax:
-a-a . = <. + 3> & ^C3
Of course. I wasn't thinking about getting it MACRO-11 correct. Initially I even
wrote (. + 3) & ~3, but then I figured that maybe using ~ for negation might not
be understood by everyone, so I started MACRO-11:fying it a little. :-)
which as pointed out ONLY works in absolute PSECTs.
Throws an error in relative PSECTs.
Yeah. That is my main issue/problem. I'd like to have one that works in relative
psects. Even though it's not perfect, it wouldn't really be any different than
what .EVEN does.
-a Johnny
On 2022-01-17 16:36, Johnny Billquist wrote:
On 2022-01-18 01:17, Don North wrote:
which as pointed out ONLY works in absolute PSECTs.
Throws an error in relative PSECTs.
Yeah. That is my main issue/problem. I'd like to have one that works
in relative psects. Even though it's not perfect, it wouldn't really
be any different than what .EVEN does.
-a-a Johnny
The problem is the standard PDP-11 linker only guarantees word alignment
for PSECTs. So enforcing a stricter alignment within a PSECT is
problematic.
On 2022-01-17 09:45, Johnny Billquist wrote:
On 2022-01-16 19:11, Jonathan Harston wrote:
If your assembler has an 'insert string' directive which takes
parameters, it's fairly simple, something like:
DS length,fillbyte
DS (($+3) BINARYAND -4)-$, 0
to align to a multiple of 4, as a general case of:
DS (($+num-1) BINARYAND -num)-$,0
where num is a power of two and $ is the location counter.
Yes, except that in Macro-11, the location counter in a normal section
is relative, and thus you are not allowed to do an AND on it. :-(
Which in a sense makes sense, since the code you are doing might be
placed on any location by the linker, thus making your computation for
an aligned address at assembler time to not be correct at all.
-a-a Johnny
If you need to produce guaranteed aligned data structures that are
aligned to
more than just a word (16b) boundary in PDP-11, and you need to do it in
a relocatable way, then writing a version of malloc(align,size) is
probably your best bet, and do the data allocation dynamically at run time.
In my recollection PDP-11 long/float quad/double (in relation to FPU in particular) did not have any alignment requirement, other than word (even).
On 2022-01-14 21:55, Lee Gleason wrote:
On 1/14/2022 11:23 AM, Johnny Billquist wrote:
On 2022-01-14 17:18, Lee Gleason wrote:
And while it's pretty straight forward in theory, I can't create such
a padding in MACRO-11. The problem is that I'm not allowed to do that
kind of arithmetic on the current location, as it is a relative value.
But maybe I'm just not creative enough right at this moment.
But with that said, I do have a MACRO-11 definition of .LONG which
works just fine. :-)
-a-a Johnny
-a-aCare to share it?
Sure. Here is both .LONG and .QUAD (yes, I occasionally need those on a PDP-11).
--------snip---------
;
; The .LONG and .QUAD macros are a bit complex since we want to handle
; all different ways of doing radix in MACRO-11.
;
; As such, they understands:
; . Default radix based on .RADIX
; . Explicit ending with . to indicate decimal
; . ^O for octal
; . ^D for decimal
; . ^X for hexadecimal
;
; Note that ^x notation requires the argument to be enclosed
; in <>, since otherwise MACRO-11 tries to parse if before
; the macro expansion happens.
;
; The variables used are:
; $$$F flag if previous char was ^
; $$$B base used for conversion
; $$$B1-$$$B8 the eight bytes accumulating the value
;
;
; $$$TD tests if the argument ends with a dot, and if so
; sets conversion base explicitly to 10.
;
-a-a-a-a-a-a-a .MACRO-a $$$TD-a-a WORD
-a-a-a-a-a-a-a .IRPC-a-a D,<WORD>
-a-a-a-a-a-a-a .IF IDN <D> .
-a-a-a-a-a-a-a $$$B=10.
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a .ENDR
-a-a-a-a-a-a-a .ENDM-a-a $$$TD
;
; $$$ADD will add one digit, in the appropriate base,
; to the accumulating bytes.
;
-a-a-a-a-a-a-a .MACRO-a $$$ADD-a DI
-a-a-a-a-a-a-a .IF EQ $$$B-8.
-a-a-a-a-a-a-a $$$V = ^O'DI
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a .IF EQ $$$B-10.
-a-a-a-a-a-a-a $$$V = ^D'DI
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a .IF EQ $$$B-16.
-a-a-a-a-a-a-a $$$V = ^X0'DI
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a .IRPC-a-a X,<12345678>
-a-a-a-a-a-a-a $$$B'X=$$$B'X*$$$B+$$$V
-a-a-a-a-a-a-a $$$V=$$$B'X/256.
-a-a-a-a-a-a-a $$$B'X=$$$B'X&^O377
-a-a-a-a-a-a-a .ENDR
-a-a-a-a-a-a-a .ENDM-a-a $$$ADD
;
; Accumulate a word into multiple bytes.
; The bytes gets into $$$Bn
;
-a-a-a-a-a-a-a .MACRO-a $$$ACC-a WORD
-a-a-a-a-a-a-a .MCALL-a $$$TD, $$$ADD
-a-a-a-a-a-a-a .IRPC-a-a X,<12345678>
-a-a-a-a-a-a-a $$$B'X=0
-a-a-a-a-a-a-a .ENDR
-a-a-a-a-a-a-a $$$F=0
-a-a-a-a-a-a-a $$$B=10
-a-a-a-a-a-a-a $$$TD-a-a <WORD>
-a-a-a-a-a-a-a .IRPC-a-a DI,<WORD>
-a-a-a-a-a-a-a .IF IDN <DI> <^>
-a-a-a-a-a-a-a $$$F=1
-a-a-a-a-a-a-a .IFF
-a-a-a-a-a-a-a .IF NE $$$F
-a-a-a-a-a-a-a .IF IDN <DI> O
-a-a-a-a-a-a-a $$$B=^O10
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a .IF IDN <DI> D
-a-a-a-a-a-a-a $$$B=10.
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a .IF IDN <DI> X
-a-a-a-a-a-a-a $$$B=^X10
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a $$$F=0
-a-a-a-a-a-a-a .IFF
-a-a-a-a-a-a-a .IF IDN <DI> .
-a-a-a-a-a-a-a .IFF
-a-a-a-a-a-a-a $$$ADD <DI>
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a .ENDR
-a-a-a-a-a-a-a .ENDM-a-a $$$ACC
-a-a-a-a-a-a-a .MACRO-a .LONG-a-a WORD,ORDER
-a-a-a-a-a-a-a .MCALL-a $$$ACC
-a-a-a-a-a-a-a $$$ACC-a <WORD>
-a-a-a-a-a-a-a $$$W1=$$$B2*256.+$$$B1
-a-a-a-a-a-a-a $$$W2=$$$B4*256.+$$$B3
-a-a-a-a-a-a-a .LIST-a-a MEB
-a-a-a-a-a-a-a .IF NB-a ORDER
-a-a-a-a-a-a-a .WORD-a-a $$$W1,$$$W2
-a-a-a-a-a-a-a .IFF
-a-a-a-a-a-a-a .WORD-a-a $$$W2,$$$W1
-a-a-a-a-a-a-a .ENDC
-a-a-a-a-a-a-a .NLIST-a MEB
-a-a-a-a-a-a-a .ENDM-a-a .LONG
-a-a-a-a-a-a-a .MACRO-a .QUAD-a-a WORD
-a-a-a-a-a-a-a .MCALL-a $$$ACC
-a-a-a-a-a-a-a $$$ACC-a <WORD>
-a-a-a-a-a-a-a $$$W1=$$$B2*256.+$$$B1
-a-a-a-a-a-a-a $$$W2=$$$B4*256.+$$$B3
-a-a-a-a-a-a-a $$$W3=$$$B6*256.+$$$B5
-a-a-a-a-a-a-a $$$W4=$$$B8*256.+$$$B7
-a-a-a-a-a-a-a .LIST-a-a MEB
-a-a-a-a-a-a-a .WORD-a-a $$$W1,$$$W2,$$$W3,$$$W4
-a-a-a-a-a-a-a .NLIST-a MEB
-a-a-a-a-a-a-a .ENDM-a-a .QUAD
---------snip---------
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 63 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 492971:17:19 |
| Calls: | 840 |
| Files: | 1,301 |
| D/L today: |
10 files (28,220K bytes) |
| Messages: | 264,287 |