• AVR Freaks

Helpful ReplyHot!MPASM to XC8 text insertion

Page: 123 > Showing page 1 of 3
Author
Bradlez
Starting Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/06/22 03:56:46
  • Location: 0
  • Status: offline
2020/06/25 05:48:23 (permalink)
0

MPASM to XC8 text insertion

Hi. I'm currently trying to migrate my assembly code from MPASM to XC8 manually (using a PIC16f886, hopefully eventually migrating to PIC16f15356) for the sake of future-proofing since the latest version of MPLAB X removed MPASM. In MPASM, I'm able to paste large chunks of text like the following:
 
; My Custom Text
 
ORG 0x1900
 
DT "This is a long piece of text that gets stored into the program memory for use.", 0x00

 
Now although the migration guide mentions that the IRP directive is the closest replacement, it doesn't allow me to do the following:
 
PSECT data, abs, ovrld
 
ORG 0x1900
 
IRP text, "This is a long piece of text that gets stored into the program memory for use.",0x00
 
    retlw text
 
ENDM

 
Now theoretically, I could chop up the text and split every single character, however that would make editing and reading the text difficult and impractical (without using some sort of script). Is there a way to achieve the same tidiness as MPASM?
 
Edit: For whoever saw this question earlier, sorry it was incomplete. I had trouble getting around the firewall issue.
post edited by Bradlez - 2020/06/25 09:39:28
#1
crosland
Super Member
  • Total Posts : 1989
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Warks, UK
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 08:22:58 (permalink)
+2 (2)
Do you have a question?
#2
Bradlez
Starting Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/06/22 03:56:46
  • Location: 0
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 09:40:50 (permalink)
+1 (1)
crosland
Do you have a question?


Sorry I had issue trying to not get the forum error message and tried to delete sections of my original question to get it to submit. I edited the original post.
#3
1and0
Access is Denied
  • Total Posts : 10906
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 10:43:24 (permalink) ☄ Helpfulby Bradlez 2020/06/27 11:07:19
+1 (1)
Give this a try:
IRPC chr, This is a long piece of text that gets stored into the program memory for use.
    retlw 'chr'
ENDM
    retlw 0

post edited by 1and0 - 2020/06/25 10:57:03
#4
Bradlez
Starting Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/06/22 03:56:46
  • Location: 0
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 11:22:36 (permalink)
0
1and0
Give this a try:
IRPC chr, This is a long piece of text that gets stored into the program memory for use.
    retlw 'chr'
ENDM
 
    retlw 0
 



Thanks! I completely skipped over this in the PDF. Will the space between the comma and the 'T' of "This" be added as a retlw ' ' though?
#5
1and0
Access is Denied
  • Total Posts : 10906
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 11:34:16 (permalink) ☄ Helpfulby Bradlez 2020/06/25 11:45:59
+2 (2)
Bradlez
 
Thanks! I completely skipped over this in the PDF. Will the space between the comma and the 'T' of "This" be added as a retlw ' ' though?

Don't be afraid to try it and see for yourself. ;)  The answer is no.
#6
Bradlez
Starting Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/06/22 03:56:46
  • Location: 0
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 12:20:08 (permalink)
0
How do I deal with other characters like a comma or an apostrophe?
#7
1and0
Access is Denied
  • Total Posts : 10906
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 13:27:18 (permalink)
+2 (2)
Bradlez
How do I deal with other characters like a comma or an apostrophe?

Good question. All I can say is do some experiments and see.
 
While the XC8 Compiler claims to conform to the C Standard, the XC8 Assembler is far from compliant; for examples,
  • a single character constant is enclosed with single quotes ' but a character string is enclosed with either double quotes " or single quotes '
  • many assembly operators are different from standard C operators, like <> instead of != for not equal to
  • etc.
#8
Antipodean
Super Member
  • Total Posts : 1857
  • Reward points : 0
  • Joined: 2008/12/09 10:19:08
  • Location: Didcot, United Kingdom
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 15:26:00 (permalink)
+1 (1)
1and0
  • many assembly operators are different from standard C operators, like <> instead of != for not equal to
  • etc.



maybe the guy that wrote it was a Basic programmer ... Smile: Smile

Do not use my alias in your message body when replying, your message will disappear ...

Alan
#9
ric
Super Member
  • Total Posts : 27652
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 15:36:04 (permalink)
+1 (1)
1and0
many assembly operators are different from standard C operators, like <> instead of != for not equal to

Really?
That seems insane.
It would be reasonable if MPASM had used those operators, but it didn't.
 

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!
#10
1and0
Access is Denied
  • Total Posts : 10906
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 18:06:04 (permalink)
+1 (1)
ric
 
Really?
That seems insane.

Here are a few more:
  • = instead of == for equality,
  • mod instead of % for modulus,
  • not instead of ~ for bitwise complement, 
  • there are no logical NOT !, logical AND &&, nor logical OR || operator, and 
  • missing a lot of the standard C operators.
#11
Bradlez
Starting Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/06/22 03:56:46
  • Location: 0
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 23:19:33 (permalink)
+1 (1)
That seems a lot like BASIC to me.
 
Edit: This paragraph was removed because this forum has some serious issues handling certain text. It was a rant of me not liking ASPIC and escape characters don't work.

My code doesn't even work even though build was successful. I might just stick with MPASM for now as this feels like a downgrade.
 
I'm not even sure if it's possible to store all my text in a separate text file and get the compiler to load the text into the PIC16f15356 at the correct locations.
post edited by Bradlez - 2020/06/25 23:21:15
#12
Bradlez
Starting Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/06/22 03:56:46
  • Location: 0
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/25 23:59:28 (permalink)
0
It would actually be amazing if it worked something like the following. Basically a macro that can be written in C and the assembler will follow it. None of the C code will be converted to instructions for the PIC, it just tells what the assembler should do.

; A build macro that tells the assembler to execute the following code on assembling the code.
BM insert_text(int loc, char txt[])
 
    int i = 0;
    while (txt[i] != '\0') {
        asm(loc + i, "retlw \'" + txt[i] + "\'"); // asm(location_to_place, instruction)
        i++;
    }
    asm(loc + i, "retlw 0x00");
ENDBM
 
; Some assembly code...
 
; Execute build macro.
EBM insert_text(0x1900, "It's cool and interesting to see\ntext like this allowed, right?")
EBM insert_text(0x1A00, "More text!!!")

 
Of course this idea isn't perfect and I probably got some terminology wrong. But this would make what I'm trying to achieve so much easier. There would probably need some adjustments to this idea to account for the fact the assembler might tend to shift code all over the place. Maybe reserve a section of the PIC's program memory so your macros have full untouched control over certain regions. An include file could be filled with useful macros, people share it on GitHub, and it doesn't bloat your program memory space.
#13
NorthGuy
Super Member
  • Total Posts : 6175
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: MPASM to XC8 text insertion 2020/06/26 09:22:08 (permalink)
0
Bradlez
It would actually be amazing if it worked something like the following. Basically a macro that can be written in C and the assembler will follow it. None of the C code will be converted to instructions for the PIC, it just tells what the assembler should do.



MPASM had macros which could do just that.
 
Without MPASM, you could compile your C fragment on PC, then run the resulting program, and either redirect the output into an include file, or paste it where you want it to be. I do such things all the time.
#14
Bradlez
Starting Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/06/22 03:56:46
  • Location: 0
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/26 23:06:43 (permalink)
0
NorthGuy
Bradlez
It would actually be amazing if it worked something like the following. Basically a macro that can be written in C and the assembler will follow it. None of the C code will be converted to instructions for the PIC, it just tells what the assembler should do.



MPASM had macros which could do just that.
 
Without MPASM, you could compile your C fragment on PC, then run the resulting program, and either redirect the output into an include file, or paste it where you want it to be. I do such things all the time.


Can you elaborate how to go about doing something similar to the idea I suggested?
#15
1and0
Access is Denied
  • Total Posts : 10906
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/27 06:54:35 (permalink)
+2 (2)
Bradlez
I might just stick with MPASM for now as this feels like a downgrade.
 

I have been saying all along that the XC8 Assembler PIC-AS is inferior to MPASM.
 
The issue here is PIC-AS is not C compliant, even though it comes bundled with a C standard conformed compiler. In fact, I think it is half vast; why have a directive that works with a character list but not accepts ALL characters!?! If it does and supports escape characters, the second argument to IRPC would be a string and work like the DT directive:
IRPC chr, "It's cool and interesting to see\ntext like this allowed, right?", 0
    retlw 'chr'
ENDM

Simple, right? But in their infinite wisdom, it is ... :(
 
#16
NorthGuy
Super Member
  • Total Posts : 6175
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: MPASM to XC8 text insertion 2020/06/27 08:12:25 (permalink) ☄ Helpfulby Bradlez 2020/06/27 11:06:49
+2 (2)
Bradlez
Can you elaborate how to go about doing something similar to the idea I suggested?



You have a C compiler on your PC, right? GCC or MSVC.
 
Then you can make your text fragment into a c file. You compile it with your C compiler on PC and it generates a text file with the assembler code which you include into your asm project.
 
You can make a script which compiles your small C program and runs it. You specify it as your pre-build script. Every time you build the project it will run the script and re-generate the include file. Thus, when you change the string in your C code, your asm source is automatically updated.
 
If you don't have a C compiler, you can use python or whatever else you like.
#17
atferrari
Super Member
  • Total Posts : 1424
  • Reward points : 0
  • Joined: 2004/07/08 13:09:24
  • Location: Buenos Aires - Argentina
  • Status: online
Re: MPASM to XC8 text insertion 2020/06/27 08:27:24 (permalink)
+2 (2)
Bradlez
How do I deal with other characters like a comma or an apostrophe?

 
This one:
 
  IRPC gree,LABEL,Date,Time,Step,Pot1,Pot2,Pot3,00DH,00AH,0

 
just inserted L A B EL and discarded the rest, including the comma.
 
With the string enclosed in quotation marks, the first one would be included (ASCII 34) and the rest again discarded all after the the L, comma included.

Agustín Tomás

In theory, there is no difference between theory and practice. In practice, however, there is.

http://cablemodem.fibertel.com.ar/atferrari/
#18
NorthGuy
Super Member
  • Total Posts : 6175
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: MPASM to XC8 text insertion 2020/06/27 08:39:21 (permalink)
+2 (2)
1and0
  • = instead of == for equality,
  • mod instead of % for modulus,
  • not instead of ~ for bitwise complement, 



This is pascal.
#19
1and0
Access is Denied
  • Total Posts : 10906
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: MPASM to XC8 text insertion 2020/06/27 09:22:45 (permalink)
+2 (2)
atferrari
This one:
 
  IRPC gree,LABEL,Date,Time,Step,Pot1,Pot2,Pot3,00DH,00AH,0

 
just inserted L A B EL and discarded the rest, including the comma.
 
With the string enclosed in quotation marks, the first one would be included (ASCII 34) and the rest again discarded all after the the L, comma included.

OP wants to know how to include the comma and apostrophe in the list to generate:
    retlw   ','
    retlw   "'"

#20
Page: 123 > Showing page 1 of 3
Jump to:
© 2020 APG vNext Commercial Version 4.5