[comp.sys.mac.programmer] MPW Assembler question

ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) (12/28/90)

I can use the "reg" directive to give a symbolic name to a set
of registers, for example

	RegsUsed  reg  d3/a2-a4

Then I can put a

	movem.l	RegsUsed, -(sp)

at the beginning of a block of code, and

	movem.l	(sp)+, RegsUsed

at the end, and if I ever change the code to use a different set of
registers, I only have to update one line to do the proper save/restore,
instead of two.

However, in this block of code, I also want to access arguments and
return results on the stack, using instructions like

	move.l	Result, 4+Something(sp)

The problem is this "Something": its value depends on the exact number
of registers in RegsUsed. I see no way of automatically computing it
from RegsUsed, for example using a hypothetical macro function as
follows:

	move.l	Result, 4+4*&NumberOfRegsIn(RegsUsed)(sp)

The only alternative seems to be to maintain the register list as
a string, and use some of the macro functions to parse this list into
its pieces myself, and not use the "reg" directive at all.

Otherwise, I have to count up the offset myself, *and* remember to
update it if the number of registers I'm using changes. More chances
for things to go wrong.

Another solution, of course, is to use a stack frame register and
offset from that to the result area. But that means saving/restoring
another register--and if I weren't worried about the overhead of this,
I wouldn't be using assembly language in the first place.

Any ideas, anybody? I agree it's only a minor inelegance, but...

Lawrence D'Oliveiro                       fone: +64-71-562-889
Computer Services Dept                     fax: +64-71-384-066
University of Waikato            electric mail: ldo@waikato.ac.nz
Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00

Lawrence.DOliveiro@f20.n226.z1.FIDONET.ORG (Lawrence DOliveiro) (12/28/90)

Reply-To: ldo@waikato.ac.nz

I can use the "reg" directive to give a symbolic name to a set
of registers, for example

        RegsUsed  reg  d3/a2-a4

Then I can put a

        movem.l RegsUsed, -(sp)

at the beginning of a block of code, and

        movem.l (sp)+, RegsUsed

at the end, and if I ever change the code to use a different set of
registers, I only have to update one line to do the proper save/restore,
instead of two.

However, in this block of code, I also want to access arguments and
return results on the stack, using instructions like

        move.l  Result, 4+Something(sp)

The problem is this "Something": its value depends on the exact number
of registers in RegsUsed. I see no way of automatically computing it
from RegsUsed, for example using a hypothetical macro function as
follows:

        move.l  Result, 4+4*&NumberOfRegsIn(RegsUsed)(sp)

The only alternative seems to be to maintain the register list as
a string, and use some of the macro functions to parse this list into
its pieces myself, and not use the "reg" directive at all.

Otherwise, I have to count up the offset myself, *and* remember to
update it if the number of registers I'm using changes. More chances
for things to go wrong.

Another solution, of course, is to use a stack frame register and
offset from that to the result area. But that means saving/restoring
another register--and if I weren't worried about the overhead of this,
I wouldn't be using assembly language in the first place.

Any ideas, anybody? I agree it's only a minor inelegance, but...

Lawrence D'Oliveiro                       fone: +64-71-562-889
Computer Services Dept                     fax: +64-71-384-066
University of Waikato            electric mail: ldo@waikato.ac.nz
Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00

 + Organization: University of Waikato, Hamilton, New Zealand

--  
Lawrence DOliveiro - via FidoNet node 1:105/14
    UUCP: ...!{uunet!glacier, ..reed.bitnet}!busker!226!20!Lawrence.DOliveiro
INTERNET: Lawrence.DOliveiro@f20.n226.z1.FIDONET.ORG