# PIC assembly: express integer constant as string at build time

One of my engineers came to me with a question that I can't answer. This is for a project using a PIC16F controller, all written in assembler.

He is defining a constant that he wants his program to use in two different ways: as an integer for use within the program and the same integer expressed as an ASCII string for use within his serial communication routines.

The standard way that I have done this in the past is to simply have the PIC convert that constant to an ASCII string at run time. However, since it is a constant, it should be possible to have the compiler do the conversion.

I've thought about it and the answer doesn't immediately come to mind.

He is defining the constant as follows:

  #DEFINE gFORCE_MIN 250


He is defining the ASCII equivalent as follows:

  #DEFINE gFORCE_MIN_STR "250"


The idea is that he modifies only one constant and the assembler automatically converts that constant into the double-quotes delimited ASCII value.

His last attempt returns the following after assembly:

  DT "gFORCE value ","gFORCE_MIN"  returns:  gFORCE value gFORCE_MIN


He is currently using MPLAB 8.92.

• The search terms you're looking for are "stringify" and "token pasting". See this over at Stack Overflow. Oct 3, 2018 at 0:53
• If you do a lot of this it might help to install the basic UTF-8 chart which includes char numbers 1 - 255. Those over 127 are considered 8 bit Unicode. The char 250 is ú.
– user105652
Oct 3, 2018 at 2:19
• @brhans Different language.
– pipe
Oct 4, 2018 at 13:47
• @Sparky256 - it's not a character code, it's a number that needs to be represented as a string. Oct 4, 2018 at 15:25