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:


He is defining the ASCII equivalent as follows:


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.

  • 4
    \$\begingroup\$ The search terms you're looking for are "stringify" and "token pasting". See this over at Stack Overflow. \$\endgroup\$
    – brhans
    Oct 3, 2018 at 0:53
  • \$\begingroup\$ 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 ú. \$\endgroup\$
    – user105652
    Oct 3, 2018 at 2:19
  • \$\begingroup\$ @brhans Different language. \$\endgroup\$
    – pipe
    Oct 4, 2018 at 13:47
  • 1
    \$\begingroup\$ @Sparky256 - it's not a character code, it's a number that needs to be represented as a string. \$\endgroup\$ Oct 4, 2018 at 15:25


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.