gnupic: gpasm: res and equates and bitfields
Subject:
Re: gpasm: res and equates and bitfields
From:
Craig Franklin ####@####.####
Date:
25 Mar 2004 02:34:50 +0000
Message-Id: <1080182055.12830.36.camel@r2d2>
On Tue, 2004-03-23 at 23:34, Scott Dattalo wrote:
> I probably should've sent this just to Craig, but maybe someone else has
> an answer.
>
> I was dabbling around in SDCC trying to figure out why bit variables are
> no longer working. One of the problems is that if an 'EQU' directive
> contains an expression with a reference to a relocatable object, then the
> 'first-pass' value is used for the relocatable object when the EQU is
> evaluated. I'm not sure if that sentence makes sense, so here's an
> example:
>
>
> bitfield1 res 1
>
> _bit0 EQU ( (bitfield0<<3)+0)
> _bit1 EQU ( (bitfield0<<3)+1)
> _bit2 EQU ( (bitfield0<<3)+2)
>
>
> The idea is that an array of named bits is created and aliased onto the
> byte reserved by the bitfield.
>
>
> Now, if you write code to access the bits:
>
> bcf _bit0 >> 3, _bit0 & 7
>
> gpasm fails to assemble it correctly. The relocatable address used to
> evaluate the EQU expressions is not correct.
>
> I suspect this is not easy to fix in gpasm. I do not know if this
> construct works with MPASM (I don't have convenient access to a Window's
> machine with MPLAB installed).
>
It doesn't work with MPASM. It will generate the "expression is too
complex" error. This is because the expression can't be reduced to
symbol + offset.
gpasm should generate the same error, but it isn't. It is because gpasm
evaluates the equ first. It looks like MPASM is passing the string.
> I've used this technique many times for creating bit fields in
> absolute-mode code. Does anyone know of a good way of creating bitfields
> in relocatable code?
>
There is no relocation for the bit argument. So the linker doesn't have
a way to patch the instructions with the bit location. This means you
have to pass the bit location at assembly time. The only thing you can
relocate are the bytes.
> Scott
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ####@####.####
> For additional commands, e-mail: ####@####.####
>