PIC: BANKMASK() - Page 1
Forum section: electronics / general

author: Dabbot
author_rank: Regular Contributor
timestamp: January 19, 2021, 08:39:48 am
content: 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.

author: Ian.M
author_rank: Super Contributor
timestamp: January 19, 2021, 09:24:17 am
content: No, MPASM just nagged you with "Message <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 useerrorlevel -302, which totally disabled bank checking or if you wanted to check for banking errors, use your own version of BANKMASK(), consisting of:Code:#define BM _cbank ^and used asCode: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?

author: Dabbot
author_rank: Regular Contributor
timestamp: January 19, 2021, 10:14:38 am
content: Quote from: Ian.M on January 19, 2021, 09:24:17 amThis, 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.Quote from: Ian.M on January 19, 2021, 09:24:17 amHorrendous

author: jpanhalt
author_rank: Super Contributor
timestamp: January 19, 2021, 10:52:50 am
content: 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.

author: NorthGuy
author_rank: Super Contributor
timestamp: January 19, 2021, 01:35:43 pm
content: Quote from: Dabbot on January 19, 2021, 08:39:48 amThis assembler was created for the C compiler, not for humans. Therefore, convenience, or usability was never a goal.