gnupic@linuxhacker.org
gnupic@linuxhacker.org
Scott Dattalo wrote:
>
> Okay, I dug into this a little more and found this in directive.c at
> around line 2824:
>
> /* Default access (use the BSR unless access is to special
> registers) */
> if ((file < 0x60) || (file > 0xf5f)) {
> a = 0;
> } else {
> a = 1;
> }
>
> In the pre-11.0 versions we had this:
>
> int a = 0; /* Default access (don't use the BSR) */
>
Yes. I changed this in 0.10.6.
> In my code, I clear BSR at the beginning so that any access to address 0
> through 0xff will always go to physical addresses 0 through 0xff. What got
> me was that an access to a variable at address 0x64 was causing the 'a'
> bit to get set. But accesses below 0x60 were not. I don't know why the
> directive.c uses 0x60 as the decision line for using the BSR or not.
> Instead it should be like this:
>
> if ((file < 0x80) || (file > 0xf7f)) {
> a = 0;
> } else {
> a = 1;
> }
>
I don't know how I made this mistake, but it is wrong. I will fix it.
> But the default behavior of the "a" bit is ambiguous. Early versions of
> MPASM are the opposite of the data sheet.
>
As much as posible, I think we should use the current version of MPASM
as the standard. This isn't always easy, but I think it would be best.
> For example, here's the description of the ANDWF instruction for the
> 18f452:
>
> The contents of W are AND ed with register 'f'. If 'd' is 0, the result is
> stored in W. If 'd' is 1, the result is stored back in register 'f'
> (default). If a is 0, the Access Bank will be selected. If a is 1, the BSR
> will not be overridden (default).
>
If you use current MPASM as the standard, their definition is not wrong,
but incomplete. For most registers, the default is 1.
> However, I know that the default is in fact a=0.
>
For all registers?
> So, it might be better to do something like this:
>
> {
> /* If the access bank is not specified, then let the default
> value be controlled by 'default_bank_select'
>
> int a = default_bank_select;
>
> /* Don't use BSR for special function registers or for
> the beginning of memory */
>
> if (!override_default_BSR && ((file < 0x80) || (file > 0xf7f)) {
> a = 0;
> }
>
> ....
>
> }
>
> Then define a new command line option:
>
> --default_BSR [0|1] - if the A bit is not specified in an 18F
> instruction then it's default value can be
> selected here. The default is 0.
>
> Now, there probably should be a warning generated for code like this:
>
> "some_reg" is at address 0x123 which is the second bank.
>
> MOVF some_reg,W,A
>
> Here we're saying *not* to use the BSR, yet our register can only be
> accessed if BSR =1 and we use:
>
> B EQU (A^1)
>
> MOVF some_reg,W,B
>
> (as an aside, I've toyed with the idea of adding a simulator assertion so
> that you could write:
>
>
> assert BSR=(some_reg>>8)
> movf some_reg,W,B
>
> )
>
> Scott
What am I missing?
The bit can be assigned a value. Its seems like a better practice the
specify it with each instruction. You wouldn't depend on the default
value to be "correct". Or, only specify it when you don't like the
default that gpasm uses.
gnupic@linuxhacker.org