MACRO-11 help

From: Pete Turnbull <pete_at_dunnington.u-net.com>
Date: Wed Sep 18 03:02:01 2002

On Sep 16, 17:40, Derek Peschel wrote:
> On Tue, Sep 17, 2002 at 12:24:02AM +0000, Pete Turnbull wrote:
> > Pat is using PC-relative addressing -- probably inadvertantly. The 67
in
> > that opcode 012767 means mode 6, PC-relative, so the address actually
used
>
> Is that why the apostrophes show up after the data? I had noticed them
> and I know what they mean (relocatable data) but I thought it might be
> the lack of correct pseudo-ops. Now I see there are no apostrophes after
> the declarations at the beginning of the file, only after the later
> references.

> I'm not sure I would have defined "relocatable" that way. (Even though
the
> program never sets . it isn't marked as relocatable, and there aren't any
> external modules that can be relocated.) But it's still a useful
definition
> if it catches errors.

Well, addressing mode 6 and 7 aren't meant merely to generate relocatable
code -- given suitable information, any linker can relocate code. Mode 6
and Mode 7 generate position-independant code (PIC), code that can be moved
at any time without alteration. The PDP-11 was designed to make that easy.

On Sep 17, 4:26, Derek Peschel wrote:

> Pete, I replied to your other post in this thread. I'm just trying to
> understand what "the right thing to do" is here.

Well, I'd say the "right thing to do" is to use absolute addressing modes.
 What modes 6/7 do is generate references which are relative to the
instruction address. They're meant for things that will move if the code
is moved (eg the target of a JSR). However, the address of a device
register doesn't move, so although it's possible to refer to using modes
6/7, it breaks the position-independance of the code. If you move the
code, you need to recalculate the address offset.

Once assembled, the first part of Pat's code, despite using mode 6, is not
PIC:

       4 177564 XSR=177564
       5 177566 XBUF=177566
       6
       7 001000 012767 000110 177566' MOV #110,XBUF
       8 001006 105767 177564' L1: TSTB XSR
       9 001012 100375 BPL L1
      10 001014 012767 000064 177566' MOV #64,XBUF
      11 001022 105767 177564' L2: TSTB XSR
      12 001026 100375 BPL L2
      13 001030 012767 000130 177566' MOV #130,XBUF

The actual values in the finally-assembled code would be (if I've done my
arithmetic correctly):

       7 001000 012767 000110 176552 MOV #110,XBUF
       8 001006 105767 176550 L1: TSTB XSR
       9 001012 100375 BPL L1
      10 001014 012767 000064 176536 MOV #64,XBUF
      11 001022 105767 176534 L2: TSTB XSR
      12 001026 100375 BPL L2
      13 001030 012767 000130 17652 2 MOV #130,XBUF

Note that the pointers to XSR and XBUF change according to their position
in the code, because they're PC-relative (even if my PC-relative arithmetic
is wrong, the differences are correct).

Now if he'd written it using absolute addresses:

       7 001000 012737 000110 177566 MOV #110,_at_#XBUF
       8 001006 105737 177564 L1: TSTB _at_#XSR
       9 001012 100375 BPL L1
      10 001014 012737 000064 177566 MOV #64,_at_#XBUF
      11 001022 105737 177564 L2: TSTB _at_#XSR
      12 001026 100335 BPL L2
      13 001030 012737 000130 177566 MOV #130,_at_#XBUF

... they don't change. Moreover, since there are no JMPs or JSRs, only
(relative) BRanches, this is PIC.

Now if he wanted to write it using a subroutine, and he used the simple
method:

       7 001000 012701 000110 MOV #'H', R1
       8 001006 004537 JSR R5, _at_#PUT
       9 001012 012701 000064 MOV #'4', R1
      10 001014 004537 JSR R5, _at_#PUT
      11 001022 012701 000130 MOV #'X', R1
      12 001026 004537 JSR R5, _at_#PUT
                          :
                          :
      35 001100 105767 177564 PUT: TSTB _at_#XSR
      36 001104 100375 BPL PUT
      37 001106 010137 177566 MOV R1, _at_#XBUF
      38 001112 000205 RTS R5

That's hand-assembled, in a hurry, so don't rely on the opcodes being
correct! but the point is that the subroutine is referred to by its
absolute address, so the first part of the code can be moved but not the
subroutine (because its address is fixed). However, if it were written
using relative addressing, ie

       8 001006 004567 JSR R5, PUT
                          :
      35 001100 105767 177564 PUT: TSTB _at_#XSR

then the whole thing can be placed anywhere in memory without alteration
(so
long as the subroutine stays in the same position relative to the rest).
 Of
course, the subroutine still uses absoute addresses for the registers.

Does that make it clear what the point of the two types of addressing is?

My example is a bit contrived; that's not really how I'd do it. Instead,
I'd write a subroutine that wrote out a whole string, the string being
stored immediately after the JSR, and returning to the word after the
string. But that's another story.

-- 
Pete						Peter Turnbull
						Network Manager
						University of York
Received on Wed Sep 18 2002 - 03:02:01 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:35:39 BST