Why doesn't the assembler automatically generate movlb (bank select) instructions?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Why doesn't the assembler automatically generate movlb (bank select) instructions?

Nathan House-5
I'm learning to program a PIC18 using assembly language and am curious
why there seems to be some redundancy with many instructions. Take the
MOVF instruction, for example:

MOVLB 0x2          ;select bank 2
MOVF   0x240, W  ;move the value at 0x240 to W

If my understanding is correct, then the "2" digit in the MOVF
instruction is ignored completely, making it redundant since the bank
is selected above. From what I've read, it seems that the assembler
automatically sets the access "a" bit based on the address when
translating to machine code, so what I'm wondering is why the
assembler doesn't automatically generate bank select instructions as
well?

Thanks!

Nathan

--
Student Hobbyist
www.roboticsguy.com
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Why doesn't the assembler automatically generate movlb (bank select) instructions?

Isaac Marino Bavaresco
The instruction 'MOVF' has only room for 8 bits of the address. The
other bits are obtained from the BSR register.

So your "movf 0x240,w" will generate the exactly same binary encoding
than a "movf 0x40,w". I think the assembler will give a warning saying
that some bits of the address will be ignored (or at least it should).


Best regards,

Isaac




Em 29/8/2012 10:21, Nathan House escreveu:

> I'm learning to program a PIC18 using assembly language and am curious
> why there seems to be some redundancy with many instructions. Take the
> MOVF instruction, for example:
>
> MOVLB 0x2          ;select bank 2
> MOVF   0x240, W  ;move the value at 0x240 to W
>
> If my understanding is correct, then the "2" digit in the MOVF
> instruction is ignored completely, making it redundant since the bank
> is selected above. From what I've read, it seems that the assembler
> automatically sets the access "a" bit based on the address when
> translating to machine code, so what I'm wondering is why the
> assembler doesn't automatically generate bank select instructions as
> well?
>
> Thanks!
>
> Nathan
>

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Why doesn't the assembler automatically generate movlb (bank select) instructions?

Jan-Erik Söderholm
In reply to this post by Nathan House-5
Nathan House wrote 2012-08-29 15:21:

> I'm learning to program a PIC18 using assembly language and am curious
> why there seems to be some redundancy with many instructions. Take the
> MOVF instruction, for example:
>
> MOVLB 0x2          ;select bank 2
> MOVF   0x240, W  ;move the value at 0x240 to W
>
> If my understanding is correct, then the "2" digit in the MOVF
> instruction is ignored completely, making it redundant since the bank
> is selected above. From what I've read, it seems that the assembler
> automatically sets the access "a" bit based on the address when
> translating to machine code, so what I'm wondering is why the
> assembler doesn't automatically generate bank select instructions as
> well?
>

It doesn't "generate" things you havn't asked for.

I'm not sure I understand, what is redundant?

Yes, if you are accessing registers in the access bank, you
do not need any BANKSEL, so just don't.

If you are accessing registers out of the access bank,
just use BANKSEL.

And if you are accessing multiple registers *in the same*
bank, just use BANKSEL *once* (and no, you do not want MPASM
to insert one MOVLB for each of the registers automaticly).


Jan-Erik.




> Thanks!
>
> Nathan
>
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Why doesn't the assembler automatically generate movlb (bank select) instructions?

Jan-Erik Söderholm
In reply to this post by Isaac Marino Bavaresco


Isaac Marino Bavaresco wrote 2012-08-29 16:04:
> The instruction 'MOVF' has only room for 8 bits of the address. The
> other bits are obtained from the BSR register.
>
> So your "movf 0x240,w" will generate the exactly same binary encoding
> than a "movf 0x40,w". I think the assembler will give a warning saying
> that some bits of the address will be ignored (or at least it should).
>

I do not think it either does or should. :-)

When you are allocating memory using UDATA and RES, you
always gets symbols with full adresses. If not, the
BANKSEL would not work on any self-allocated variables,
BANKSEL would not be able to calculate the actual bank.

And you would get *a lot* of warnings also... :-)

Jan-Erik.


>
> Best regards,
>
> Isaac
>
>
>
>
> Em 29/8/2012 10:21, Nathan House escreveu:
>> I'm learning to program a PIC18 using assembly language and am curious
>> why there seems to be some redundancy with many instructions. Take the
>> MOVF instruction, for example:
>>
>> MOVLB 0x2          ;select bank 2
>> MOVF   0x240, W  ;move the value at 0x240 to W
>>
>> If my understanding is correct, then the "2" digit in the MOVF
>> instruction is ignored completely, making it redundant since the bank
>> is selected above. From what I've read, it seems that the assembler
>> automatically sets the access "a" bit based on the address when
>> translating to machine code, so what I'm wondering is why the
>> assembler doesn't automatically generate bank select instructions as
>> well?
>>
>> Thanks!
>>
>> Nathan
>>
>
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Why doesn't the assembler automatically generate movlb (bank select) instructions?

Rupert Swarbrick-2
In reply to this post by Nathan House-5
Nathan House <[hidden email]> writes:

> I'm learning to program a PIC18 using assembly language and am curious
> why there seems to be some redundancy with many instructions. Take the
> MOVF instruction, for example:
>
> MOVLB 0x2          ;select bank 2
> MOVF   0x240, W  ;move the value at 0x240 to W
>
> If my understanding is correct, then the "2" digit in the MOVF
> instruction is ignored completely, making it redundant since the bank
> is selected above. From what I've read, it seems that the assembler
> automatically sets the access "a" bit based on the address when
> translating to machine code, so what I'm wondering is why the
> assembler doesn't automatically generate bank select instructions as
> well?

Well, if you access several locations in the same bank in a row, you
only need to use one MOVLB (or BANKSEL) command. Emitting one before
each access would halve the speed at which your program ran...

Rupert

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist