• AVR Freaks

AnsweredHot!Migrane (a headache to migrate) MPASM to pic-as

Page: 12 > Showing page 1 of 2
Author
MIS42N
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2014/02/25 23:36:37
  • Location: 0
  • Status: offline
2020/08/08 01:20:25 (permalink)
5 (1)

Migrane (a headache to migrate) MPASM to pic-as

I wrote an assembler program for a PIC16F628A which is over 1000 lines of code. This was debugged and running fine using MPLAB X IDE v5.3x. I find v5.4 won't touch it because the assembler is now pic-as not MPASM. I've been working my way through just trying to get it error free and I'm not sure if I've missed something vital or pic-as is a contraction of PartICularly-ASinine. For instance, I used PSECT udata_bank2 to store a few variables and get 'fixup overflow referencing psect udata_bank2' and as far as I can find out I have to redefine all my variables e.g. REGC0 is now:
RRC0:        DS    1   ; lsb
#define REGC0 BANKMASK(RRC0)
which seems ludicrous. Obviously I want the variables addressed in Bank 2 using 7 bit addresses and it's up to me to make sure the bank switching is OK. MPASM was quite happy to truncate the address before handing to linker so why doesn't pic-as? Why do I have to redefine every variable with this BANKMASK rubbish (the #define makes the code more readable and compact than adding a BANKMASK to every instruction).
I was wondering if I should define all the banks as overlays of bank 0. Haven't tried it but maybe it would work.
And do I need to give every bit a name?
I tried a bit operation like btfss REGC0, 5 but it gives a syntax error. I ended up writing #define REGC0_5 BANKMASK(RRC0) ,5
I am thinking to rewrite the application, with enhancements, for a PIC16F1455. I am comfortable with assembler and have no desire to use C. The program will have to handle over 40,000 interrupts a second and runs several threads, not quite sure how C would handle it.
What did I miss?
#1
sdn_
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/03/08 02:14:28
  • Location: 0
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/08 01:39:26 (permalink)
0
p.s.
Example:
PSECT myBitAccessVar,space=1,class=BANK5,bit
         bit_var     ds 1
post edited by sdn_ - 2020/08/08 01:42:43
#2
ric
Super Member
  • Total Posts : 28378
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/08 01:40:06 (permalink) ☼ Best Answerby MIS42N 2020/08/08 02:41:32
+2 (4)
pic-as really is not mature yet.
Why not stick with MPLABX v5.3x? It supports all the devices you want to use just fine.
I'd wait until v5.45 before getting serious about pic-as.
 

The program will have to handle over 40,000 interrupts a second and runs several threads, not quite sure how C would handle it.

It should be perfectly doable in C. I'm not sure what one of your "threads" entails, but if you managed it in ASM you can probably do it in C.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#3
sdn_
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/03/08 02:14:28
  • Location: 0
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/08 01:43:58 (permalink)
0
Declare a bit variable for flags. Then the bankmask will not be needed.
p.s.
Example:
PSECT myBitAccessVar,space=1,class=BANK5,bit
         bit_var     ds 1
#4
ric
Super Member
  • Total Posts : 28378
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/08 02:19:41 (permalink)
-1 (1)
sdn_
Declare a bit variable for flags. Then the bankmask will not be needed.

I think you are misunderstanding what BANKMASK is.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#5
sdn_
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/03/08 02:14:28
  • Location: 0
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/08 02:25:01 (permalink)
0
The question was about how to get rid of the bankmask text.
#6
MIS42N
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2014/02/25 23:36:37
  • Location: 0
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/08 03:29:00 (permalink)
0
Yes maybe stick with what I know. I guess not too many people write pure assembler programs any more. Probably what I want to do could be done in a more powerful processor in C, but my bent is to get the most bang for buck.
 
In answer to ric, there are a few time critical things to do. One is to deal with a TMR2 interrupt every 250 instruction times, so I can't have interrupts disabled too long. But there are other interrupts to service which take a while. So I save all the status elsewhere and enable interrupts, the threads wander along until completion then restore status and do a RET to go back to the background task or another interrupted thread. The background task soaks up most of what is left of cycles so not in a position to poll.
 
And yes, I absolutely don't understand why this BANKMASK thing exists. I read it has something to do with the linker maybe not allocating data to the bank you thought it would, and using a BANKMASK as an exclusive or will throw up an error if the linker tries to put it somewhere else. If that is the case, then it seems totally obvious that if I write
PSECT udata_bank2
Then pic-as would automatically pass to the linker the exclusive or for bank2 because that's what I told it I wanted. Instead it seems BANKMASK is defined as AND 0x7F which means the linker can't say if it got wrongly allocated.
 
Abort, abort, abort. Back to MPASM
#7
dan1138
Super Member
  • Total Posts : 3843
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/08 11:15:04 (permalink)
0
sdn_
Declare a bit variable for flags. Then the BANKMASK will not be needed.

p.s.
Example:
 PSECT myBitAccessVar,space=1,class=BANK5,bit
bit_var ds 1


Section 7. Interrupts and Bits Example, from the "official" Microchip documentation:
;bits in bank 0 data memory
GLOBAL needCopy
PSECT myFlags,space=1,class=BANK0,bit
needCopy: DS 1

This is where the bit is used in an interrupt service routine:

;set a flag to say that the port should be incremented
BANKSEL (needCopy/8)
bsf BANKMASK(needCopy/8),needCopy&7

It would seem that the BANKSEL and BANKMASK directives are required.
#8
sdn_
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/03/08 02:14:28
  • Location: 0
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/08 13:12:31 (permalink)
0
#include <xc.inc>
PSECT myBitAccessVar,space=1,class=BANK5,bit
bit_var: ds 1

psect code, abs
main:
ORG 0X00
 
movlb 0x05
BSF bit_var/8,bit_var
 
END main
 
#9
sdn_
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/03/08 02:14:28
  • Location: 0
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/08 13:19:15 (permalink)
0
You can also work with a byte variable.
You need to keep track of the size of the zero bank relative to the bank that you actually use in your program.
 
#include <xc.inc>
PSECT myByteBankedVar,space=1,class=BANK0
BYTE_VAR: ds 1
 
PSECT myBitAccessVar,space=1,class=BANK0,bit
bit_var: ds 1

psect code, abs
main:
ORG 0X00
movlb 0x05
BSF bit_var/8,bit_var
CLRF BYTE_VAR
END main
#10
dan1138
Super Member
  • Total Posts : 3843
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/08 14:15:11 (permalink)
0
sdn_
#include <xc.inc>
PSECT myBitAccessVar,space=1,class=BANK5,bit
bit_var: ds 1
 
psect code, abs
main:
ORG 0X00
 
movlb 0x05
BSF bit_var/8,bit_var
 
END main

This only seems to work for opcodes that work on bits.

sdn_
You can also work with a byte variable.
You need to keep track of the size of the zero bank relative to the bank that you actually use in your program.
 
#include <xc.inc>
PSECT myByteBankedVar,space=1,class=BANK0
BYTE_VAR: ds 1
 
PSECT myBitAccessVar,space=1,class=BANK0,bit
bit_var: ds 1
 
psect code, abs
main:
ORG 0X00
movlb 0x05
BSF bit_var/8,bit_var
CLRF BYTE_VAR
END main

Your example builds without errors only because you selected bank zero.

This is a complete application for a specific PIC controller that can be used to verify my observations.
; PIC18F47Q10 Configuration Bit Settings
;
 config FEXTOSC = OFF, RSTOSC = HFINTOSC_64MHZ, CLKOUTEN = OFF
 config CSWEN = ON, FCMEN = ON, MCLRE = EXTMCLR, PWRTE = OFF
 config LPBOREN = OFF, BOREN = SBORDIS, BORV = VBOR_190, ZCD = OFF
 config PPS1WAY = OFF, STVREN = ON, XINST = OFF, WDTCPS = WDTCPS_31
 config WDTE = OFF, WDTCWS = WDTCWS_7, WDTCCS = SC
 config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
 config WRT4 = OFF, WRT5 = OFF, WRT6 = OFF, WRT7 = OFF
 config WRTC = OFF, WRTB = OFF, WRTD = OFF, SCANE = ON
 config CP = OFF, CPD = OFF, LVP = ON, EBTRB = OFF
 config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
 config EBTR4 = OFF, EBTR5 = OFF, EBTR6 = OFF, EBTR7 = OFF
;
#include <xc.inc>
;
    PSECT   myBitAccessVar,space=1,class=BANK5,bit
    global  bit_var
bit_var: ds 1
;
    psect code, abs
    global  main
    ORG     0x00
;
main:
    movlw   1<<(bit_var&7)
    movlb   high(bit_var/8)
    btg     bit_var/8,bit_var,b   ; pic-as ignores upper address bits of a relocatable object on bit opcodes
    xorwf   (bit_var/8)    ,f,b   ; pic-as asserts error when upper address bits of a relocatable object are not masked on byte opcodes
;   xorwf   (bit_var/8)&127,f,b   ; this statement builds without errors
    bra     main
 ;
    END     main

This is what the build output looks like for me:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Public/GitRepo/Projects/PIC/PIC18F47Q10_bits.X'
make  -f nbproject/Makefile-default.mk dist/default/production/PIC18F47Q10_bits.X.production.hex
make[2]: Entering directory 'C:/Public/GitRepo/Projects/PIC/PIC18F47Q10_bits.X'
"C:\PIC_dev\MPLABXC\xc8\v2.20\pic-as\bin\pic-as.exe" -mcpu=PIC18F47Q10 -c \
-o build/default/production/main.o \
main.S \
 -misa=std -msummary=+mem,+psect,-class,-hex,-file,-sha1,-sha256,-xml,-xmlfull -fmax-errors=20 -mwarn=0 -xassembler-with-cpp
"C:\PIC_dev\MPLABXC\xc8\v2.20\pic-as\bin\pic-as.exe" -mcpu=PIC18F47Q10 build/default/production/main.o \
-o dist/default/production/PIC18F47Q10_bits.X.production.hex \
 -misa=std -msummary=+mem,+psect,-class,-hex,-file,-sha1,-sha256,-xml,-xmlfull -mcallgraph=std -mno-download-hex
main.S:29:: error: (1357) fixup overflow storing 0x500 in 1 byte at 0x6/0x1 -> 0x6 (build/default/production/main.o 50/0x6)
(908) exit status = 1
nbproject/Makefile-default.mk:126: recipe for target 'dist/default/production/PIC18F47Q10_bits.X.production.hex' failed
make[2]: Leaving directory 'C:/Public/GitRepo/Projects/PIC/PIC18F47Q10_bits.X'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Public/GitRepo/Projects/PIC/PIC18F47Q10_bits.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [dist/default/production/PIC18F47Q10_bits.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 1s)

post edited by dan1138 - 2020/08/08 14:36:59
#11
sdn_
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/03/08 02:14:28
  • Location: 0
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/09 02:10:52 (permalink)
-1 (1)
dan1138
Your example builds without errors only because you selected bank zero.
 



Further, in the text of the program, you see movlb 0x05. This way I use the fifth bank without adding the text "bankmask".
#12
1and0
Access is Denied
  • Total Posts : 11140
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/09 04:34:16 (permalink)
0
sdn_
 
Further, in the text of the program, you see movlb 0x05. This way I use the fifth bank without adding the text "bankmask".

Wow... I hope you don't write your code this way -- defining all variables in bank 0 and using the symbols as in bank 5. What do you think will happen when you have more than 80 symbols bytes defined in bank 0?
post edited by 1and0 - 2020/08/09 04:38:15
#13
1and0
Access is Denied
  • Total Posts : 11140
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/09 04:49:55 (permalink)
+1 (1)
MIS42N
And yes, I absolutely don't understand why this BANKMASK thing exists. I read it has something to do with the linker maybe not allocating data to the bank you thought it would, and using a BANKMASK as an exclusive or will throw up an error if the linker tries to put it somewhere else. If that is the case, then it seems totally obvious that if I write
PSECT udata_bank2
Then pic-as would automatically pass to the linker the exclusive or for bank2 because that's what I told it I wanted. Instead it seems BANKMASK is defined as AND 0x7F which means the linker can't say if it got wrongly allocated.

I asked the same question in Post #4 [link=https://www.microchip.com/forums/FindPost/740092]here[/link] back in 2013 and again in Post #22 [link=https://www.microchip.com/forums/FindPost/1102304]here[/link] in 2019, but Jeff from the XC8 team did not give me an answer :(
 
 
#14
1and0
Access is Denied
  • Total Posts : 11140
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/09 05:20:11 (permalink)
0 (2)
I meant I asked the same question in Post #5 which I'll quote here:
1and0
XC8 User's Guide
In most cases, fixup errors are caused by hand-written assembly code. When writing assembly, it is the programmer’s responsibility to add instructions to select the destination bank or page, and then mask the address being used in the instruction

The compiler knows the size of the address field in the instruction. Is it so dumb that it cannot just perform the truncation automatically, instead of having the programmer manually masks it? MPASM does the truncation automatically, surely a C compiler is smarter than it? ... and it would make for less-cluttered code, not to mention less typing too. ;)

post edited by 1and0 - 2020/08/09 06:38:44
#15
ric
Super Member
  • Total Posts : 28378
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/09 05:38:12 (permalink)
0
So we all have to endure this pain to support a feature that was never implemented...
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#16
1and0
Access is Denied
  • Total Posts : 11140
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/09 05:44:48 (permalink)
+1 (1)

Section 7. Interrupts and Bits Example, from the "official" Microchip documentation:
;bits in bank 0 data memory
GLOBAL needCopy
PSECT myFlags,space=1,class=BANK0,bit
needCopy: DS 1

This is where the bit is used in an interrupt service routine:

;set a flag to say that the port should be incremented
BANKSEL (needCopy/8)
bsf BANKMASK(needCopy/8),needCopy&7

It would seem that the BANKSEL and BANKMASK directives are required.

Sigh ... here "needCopy" is defined as a "bit" so why in Microchip's infinite wisdom to access this bit like this
bsf BANKMASK(needCopy/8),needCopy&7
when it is much much cleaner to implement this
bsf needCopy

???  Before any reply, I know what the /8 and &7 do. ;)
#17
1and0
Access is Denied
  • Total Posts : 11140
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/09 05:50:08 (permalink)
+1 (1)
ric
So we all have to endure this pain to support a feature that was never implemented...

Sadly, common sense is actually not so common. ;)
 
#18
sdn_
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/03/08 02:14:28
  • Location: 0
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/09 06:07:58 (permalink)
0
1and0
sdn_
 
Further, in the text of the program, you see movlb 0x05. This way I use the fifth bank without adding the text "bankmask".

Wow... I hope you don't write your code this way -- defining all variables in bank 0 and using the symbols as in bank 5. What do you think will happen when you have more than 80 symbols bytes defined in bank 0?


 
sdn_You need to keep track of the size of the zero bank relative to the bank that you actually use in your program.

https://www.microchip.com/forums/FindPost/1149899
 



#19
1and0
Access is Denied
  • Total Posts : 11140
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Migrane (a headache to migrate) MPASM to pic-as 2020/08/09 06:11:36 (permalink)
+1 (1)
1and0
... and it would make for less-cluttered code, not to mention less typing too. ;)

The way I (fore)see this, BANKMASK() will be the most used macro/mess in a PIC-AS source file. ;)
post edited by 1and0 - 2020/08/09 06:39:21
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5