Author Topic: PIC: BANKMASK()  (Read 3175 times)

0 Members and 1 Guest are viewing this topic.

Offline DabbotTopic starter

  • Regular Contributor
  • *
  • Posts: 198
  • Country: au
PIC: BANKMASK()
« on: January 19, 2021, 08:39:48 am »
This is a gripe, not any kind of show stopper.

Why does pic-as insist I use BANKMASK() for non-bank0 SFRs and objects placed in the GPRAM PSECTs?

If all that BANKMASK() does is zero out all but the offset bits of a given address, why can't the assembler just do that automatically? The assembler already knows what the instruction expects.

What does BANKMASK() do that automatically supplying the object's bank offset to the given instruction not do? There's a legitimate use case for this macro that I'm missing. What is it?

I ask because wrapping everything up in BANKMASK() all the time is getting annoying. I didn't have to do this in MPASM.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14140
Re: PIC: BANKMASK()
« Reply #1 on: January 19, 2021, 09:24:17 am »
No, MPASM just nagged you with "Message[302] <filename.asm> <line>: Register in operand not in bank 0. Ensure that bank bits are correct".

If you wanted a clean build you had to either use errorlevel -302, which totally disabled bank checking or if you wanted to check for banking errors, use your own version of BANKMASK(), consisting of:
Code: [Select]
#define BM _cbank ^and used as
Code: [Select]
          movwf BM TRISAand also keep _cbank up to date, by writing your own macros to replace BANKSEL and BANKISEL that updated it as well as generating the bank selection code.  Additionally one needed a 'BANKSMASH' macro that could be used at jump and call targets, which made _cbank -1, which would give a message 302 for *any* legal register address, so if you were entering a routine with an unknown bank selected, you could raise an error if SFRs were accessed before a definite bank selection was made.

If a future version of XC8 switched BANKMASK() to XOR masking with the tracked current bank, it might actually become useful.

The XC8 assembler pic-as (formerly aspic) is incredibly annoying anyway.  e.g. Its ridiculous that nearly 12 years after Microchip acquired Hi-Tech, you still need to create a dummy C function, carefully tweaked NOT to optimize away parameters or the return value, compile it and trawl through the assembly listing to get the magic SIGNAT number to let you link a pure assembler module with C code!

Another major idiocy is the depreciation of #asm and #endasm.   Having to wrap each inline assembly line of code in C source strings in individual asm() statements is just barbaric!  Surely there could have been a better way of doing this, maybe using C preprocessor #pragma syntax?
« Last Edit: January 19, 2021, 09:26:40 am by Ian.M »
 

Offline DabbotTopic starter

  • Regular Contributor
  • *
  • Posts: 198
  • Country: au
Re: PIC: BANKMASK()
« Reply #2 on: January 19, 2021, 10:14:38 am »
If a future version of XC8 switched BANKMASK() to XOR masking with the tracked current bank, it might actually become useful.
This, and if the BANKMASK() happened behind the scenes, it would be incredibly useful. I just can't see why it needs to be explicitly done by the user / compiler, if it effectively needs to be done every time.

Another major idiocy is the depreciation of #asm and #endasm.   Having to wrap each inline assembly line of code in C source strings in individual asm() statements is just barbaric!  Surely there could have been a better way of doing this, maybe using C preprocessor #pragma syntax?
:palm: Horrendous
 

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 4864
  • Country: us
Re: PIC: BANKMASK()
« Reply #3 on: January 19, 2021, 10:52:50 am »
Which PIC are you using?  With mid-range devices, the core is only 14-bits wide.  That limits the number of locations the opcode can address.  Hence, you need to use banksel (an Assembly directive that may be available for your chip), movlb (select the bank manually for enhanced mid-range), or some other way, such as setting the upper 2 bits of the STATUS register, for older chips.

As you move to large cores, e.g, 18Fxxx and above, bank changing is less of a chore. 

I use enhanced  mid-range chips, Assembly language, and track the bank I am in.  I will also use general purpose RAM in different banks to minimize bank switching for specific routines, such as clearing an SPI-interface GLCD screen for which virtually the entire subroutine is in bank 4.  Some people don't do that and use "banksel" everytime they use any SFR.  The latter causes a lot of clutter in my opinion, but it is a matter of choice.
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3593
  • Country: ca
Re: PIC: BANKMASK()
« Reply #4 on: January 19, 2021, 01:35:43 pm »
What does BANKMASK() do that automatically supplying the object's bank offset to the given instruction not do? There's a legitimate use case for this macro that I'm missing. What is it?

This assembler was created for the C compiler, not for humans. Therefore, convenience, or usability was never a goal.
 
The following users thanked this post: Ian.M


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->