XC8: .asm to C ( i.e. Lowering One's Expectations)

Jolly13

Joined Mar 25, 2018
44
The waning is straight forward the we have deferent semantic meaning for Message. Make them the same ?
C has no such thing as a string.

You are declaring a single array of bytes in ram with 3 null terminated string in it. not 3 strings.

Think.

constantName TEXTEQU <""Line 1 Init msg\0Line 2 Init msg \0 \0">
.cdata
messages BYTE constantName


An array of strings is usually. Char * name[]; in c

Think about C as a pseudo macro assembler,
Give me a location to initialized ram that has this name and is this size and put this in it .

I do find suppressing warning is not a great thing , at some point you will wish it would help find things. ,

If what you want is a consecutive chunk of ram then change the definition to one chunk not 3 make it match your definition.
Like this **Note no comma's** if you want the null char also add them you self ( i believe for all but last one) . and compiler will not get confused and nag you .

const char messages[] = "Line 1 Init msg\0" "Line 2 Init msg \0" " "

MY eyes like this one better and exact same outcome a bunch of byes in ram with data initialized to this and named messages.
const char * messages = "Line 1 Init msg\0Line 2 Init msg \0 ";
 

Jolly13

Joined Mar 25, 2018
44
The waning is straight forward the we have deferent semantic meaning for Message. Make them the same ?
C has no such thing as a string.

You are declaring a single array of bytes in ram with 3 null terminated string in it. not 3 strings.

Think.

constantName TEXTEQU <""Line 1 Init msg\0Line 2 Init msg \0 \0">
.cdata
messages BYTE constantName


An array of strings is usually. Char * name[]; in c

Think about C as a pseudo macro assembler,
Give me a location to initialized ram that has this name and is this size and put this in it .

I do find suppressing warning is not a great thing , at some point you will wish it would help find things. ,

If what you want is a consecutive chunk of ram then change the definition to one chunk not 3 make it match your definition.
Like this **Note no comma's** if you want the null char also add them you self ( i believe for all but last one) . and compiler will not get confused and nag you .

const char messages[] = "Line 1 Init msg\0" "Line 2 Init msg \0" " "

MY eyes like this one better and exact same outcome a bunch of byes in ram with data initialized to this and named messages.
const char * messages = "Line 1 Init msg\0Line 2 Init msg \0 ";
Hmm how to insert code block with out my text getting mucked with :(
 

Thread Starter

joeyd999

Joined Jun 6, 2011
6,324
The waning is straight forward the we have deferent semantic meaning for Message. Make them the same ?
C has no such thing as a string.

You are declaring a single array of bytes in ram with 3 null terminated string in it. not 3 strings.

Think.

constantName TEXTEQU <""Line 1 Init msg\0Line 2 Init msg \0 \0">
.cdata
messages BYTE constantName


An array of strings is usually. Char * name[]; in c

Think about C as a pseudo macro assembler,
Give me a location to initialized ram that has this name and is this size and put this in it .

I do find suppressing warning is not a great thing , at some point you will wish it would help find things. ,

If what you want is a consecutive chunk of ram then change the definition to one chunk not 3 make it match your definition.
Like this **Note no comma's** if you want the null char also add them you self ( i believe for all but last one) . and compiler will not get confused and nag you .

const char messages[] = "Line 1 Init msg\0" "Line 2 Init msg \0" " "

MY eyes like this one better and exact same outcome a bunch of byes in ram with data initialized to this and named messages.
const char * messages = "Line 1 Init msg\0Line 2 Init msg \0 ";
Thanks for playing, @Jolly13 . You answered a 2 year old question that has both been answered, and is no longer the topic of this thread.

One should read long threads to get a feel for them prior to jumping in.
 

Thread Starter

joeyd999

Joined Jun 6, 2011
6,324
YA would think the home page would not drop to active thread list 1 of 5 or so " LATEST FORUM THREADS " .. .. surprised it pop into that list
Will look at dates in future hmm
It's an active thread. But it has evolved over the years, and there have been 466 posts (including this one), in the interim.

Edit: the noise doesn't bother me. In fact, there are some Crazy Eyed weirdos that like to spam my threads with random nonsense. They are just ignored.

Please enjoy the thread, and pitch in where you think you can be helpful.
 

BobaMosfet

Joined Jul 1, 2009
2,211
Hey, @nsaspook, I'm working on a PIC project in C. I feel icky all over.

In any case, I've got this code to declare and initialize an array of strings:

C:
const char * messages[] =   {
                            "Line 1 Init msg",    //m_init1
                            "Line 2 Init msg ",   //m_init2
                            "                "    //m_blank
};
The code compiles and runs as expected, but I get this compiler warning:



What the heck does this mean?
Is the header file 'messages.h' yours? If not, that is a compiler library header and it's telling you that you've redeclared the symbol 'messages' and your declaration is different from that on line 33 of the specified header file. DO NOT prepend variables with an underscore in C- frequently that is done only in libraries (sometimes to reference asm registers, etc). I recognize it's common asm, but causes conflict here :)
 

Thread Starter

joeyd999

Joined Jun 6, 2011
6,324
Is the header file 'messages.h' yours? If not, that is a compiler library header and it's telling you that you've redeclared the symbol 'messages' and your declaration is different from that on line 33 of the specified header file. DO NOT prepend variables with an underscore in C- frequently that is done only in libraries (sometimes to reference asm registers, etc). I recognize it's common asm, but causes conflict here :)
https://forum.allaboutcircuits.com/...owering-ones-expectations.190219/post-1910237
 

Thread Starter

joeyd999

Joined Jun 6, 2011
6,324
A few years later, how's it going? Your posted C code examples look great.
Success on a few projects. I'm competent.

But, still, just plain annoying.

Old dogs and new tricks and all that.

There's nothing hard about C. Just .asm is quicker and easier for the things I do.

Here's a stupid function to paint 5 panels of 8x8 RGB LEDs that's fast enough to reliably paint all five panels:

C:
void WS_doPaint(void)
{
    static volatile uint8_t panel, dblrow, pixcnt, bitcnt, pixel, bright;
    static volatile uint8_t red, green, blue;
  
    if (!PPSTAT_TCL)
        return;
      
    bright = ws_brightness;
  
    asm("BANKSEL " ___mkstr(WS_doPaint@pixel));

// FSR1 -> Frame Buffer

    asm("movlw  low (_ws_framebuffer)");
    asm("movwf" ___mkstr(BANKMASK(FSR1L)) ",0");
    asm("movlw  high (_ws_framebuffer)");
    asm("movwf" ___mkstr(BANKMASK(FSR1H)) ",0");

// Iterate through panels 
    
//  for (panel = 0; panel < WS_NUM_PANELS; panel++)
//  {
    asm("movlw "  ___mkstr(WS_NUM_PANELS));
    asm("movwf"   ___mkstr(BANKMASK(WS_doPaint@panel))",1");
    asm("panelloop:");
  
//  every other row alternates direction 
  
//      for (dblrow=0; dblrow<(WS_NUM_ROWS / 2); dblrow++)
//      {
        asm("movlw "  ___mkstr(WS_NUM_ROWS)"/2");
        asm("movwf"   ___mkstr(BANKMASK(WS_doPaint@dblrow))",1");
        asm("rowloop:");
  
//Even rows -> Increasing pixels

//          for (pixcnt=0; pixcnt<WS_NUM_COLS*3; pixcnt++)
//          {
            asm("movlw "  ___mkstr(WS_NUM_COLS)"*3");
            asm("movwf"   ___mkstr(BANKMASK(WS_doPaint@pixcnt))",1");
            asm("pixloopi:");
  
                asm("movff"  ___mkstr(BANKMASK(INDF1)) "," ___mkstr(WS_doPaint@pixel));
                asm("movf"   ___mkstr(BANKMASK(WS_doPaint@bright))",0,1");
                asm("mulwf"  ___mkstr(BANKMASK(POSTINC1))",0");
                asm("btfss"  ___mkstr(BANKMASK(STATUS)) "," ___mkstr(_STATUS_Z_POSITION) ",0");
                asm("movff   PRODH," ___mkstr(WS_doPaint@pixel));

//              for (bitcnt=0; bitcnt<8; bitcnt++)
//              {
                asm("movlw 8");
                asm("movwf"   ___mkstr(BANKMASK(WS_doPaint@bitcnt))",1");
                asm("bitloop1:");
              
                    asm("bcf"   ___mkstr(BANKMASK(INTCON0)) "," ___mkstr(_INTCON0_GIE_POSITION) ",0"); //disable int -- 1187.5ns   (0) / 1.1875ns
                    asm("bsf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //start high  --    0.0ns   (1) / 1250.0ns
                    asm("rlcf"  ___mkstr(BANKMASK(WS_doPaint@pixel))",1,1");                                      //shift bit   --   62.5ns   (1)
                    asm("bra    $+2");                                                                 //nop*2       --  125.0ns   (1)
                    asm("btfss" ___mkstr(BANKMASK(STATUS)) "," ___mkstr(_STATUS_C_POSITION) ",0");     //test bit    --  375.0ns   (1)
                    asm("bcf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //short pulse --  437.5ns   (0/1)
                    asm("bra    $+2");                                                                 //nop*2       --  500.0ns   (0/1)
                    asm("bcf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //long pulse  --  875.0ns   (0)
                    asm("bsf"   ___mkstr(BANKMASK(INTCON0)) "," ___mkstr(_INTCON0_GIE_POSITION) ",0"); //enable int  --  937.5ns   (0)
                  
                  
                asm("decfsz"   ___mkstr(BANKMASK(WS_doPaint@bitcnt))",1,1");
                asm("bra bitloop1");
//              } //bitcnt

            asm("decfsz"   ___mkstr(BANKMASK(WS_doPaint@pixcnt))",1,1");
            asm("bra pixloopi");
//          } //pixcnt

            asm("movlw low(8 * 3 * 5 - 3 + 1 )");
            asm("addwf"  ___mkstr(BANKMASK(FSR1L)) ",1,0");
            asm("movlw high(8 * 3 * 5 - 3)");
            asm("addwfc" ___mkstr(BANKMASK(FSR1H)) ",1,0");

//odd rows -> decreasing pixels

//          for (pixcnt=0; pixcnt<WS_NUM_COLS; pixcnt++)
//          {

            asm("movlw "  ___mkstr(WS_NUM_COLS));
            asm("movwf"   ___mkstr(BANKMASK(WS_doPaint@pixcnt))",1");
            asm("pixloopd:");


                asm("movff"  ___mkstr(BANKMASK(INDF1)) "," ___mkstr(WS_doPaint@pixel));
                asm("movf"   ___mkstr(BANKMASK(WS_doPaint@bright))",0,1");
                asm("mulwf"  ___mkstr(BANKMASK(POSTINC1))",0");
                asm("btfss"  ___mkstr(BANKMASK(STATUS)) "," ___mkstr(_STATUS_Z_POSITION) ",0");
                asm("movff   PRODH," ___mkstr(WS_doPaint@pixel));

//              for (bitcnt=0; bitcnt<8; bitcnt++)
//              {
                asm("movlw 8");
                asm("movwf"   ___mkstr(BANKMASK(WS_doPaint@bitcnt))",1");
                asm("bitloop2:");
              
                    asm("bcf"   ___mkstr(BANKMASK(INTCON0)) "," ___mkstr(_INTCON0_GIE_POSITION) ",0"); //disable int -- 1187.5ns   (0) / 1.1875ns
                    asm("bsf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //start high  --    0.0ns   (1) / 1250.0ns
                    asm("rlcf"  ___mkstr(BANKMASK(WS_doPaint@pixel))",1,1");                                      //shift bit   --   62.5ns   (1)
                    asm("bra    $+2");                                                                 //nop*2       --  250.0ns   (1)
                    asm("btfss" ___mkstr(BANKMASK(STATUS)) "," ___mkstr(_STATUS_C_POSITION) ",0");     //test bit    --  375.0ns   (1)
                    asm("bcf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //short pulse --  437.5ns   (0/1)
                    asm("bra    $+2");                                                                 //nop*2       --  750.0ns   (0/1)
                    asm("bcf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //long pulse  --  875.0ns   (0)
                    asm("bsf"   ___mkstr(BANKMASK(INTCON0)) "," ___mkstr(_INTCON0_GIE_POSITION) ",0"); //enable int  --  937.5ns   (0)

                asm("decfsz"   ___mkstr(BANKMASK(WS_doPaint@bitcnt))",1,1");
                asm("bra bitloop2");
//              }

                asm("movff"  ___mkstr(BANKMASK(INDF1)) "," ___mkstr(WS_doPaint@pixel));
                asm("movf"   ___mkstr(BANKMASK(WS_doPaint@bright))",0,1");
//                asm("mulwf"  ___mkstr(BANKMASK(POSTINC1))",0");
                asm("mulwf"  ___mkstr(BANKMASK(POSTDEC1))",0");
                asm("btfss"  ___mkstr(BANKMASK(STATUS)) "," ___mkstr(_STATUS_Z_POSITION) ",0");
                asm("movff   PRODH," ___mkstr(WS_doPaint@pixel));

//              for (bitcnt=0; bitcnt<8; bitcnt++)
//              {
                asm("movlw 8");
                asm("movwf"   ___mkstr(BANKMASK(WS_doPaint@bitcnt))",1");
                asm("bitloop3:");
              
                    asm("bcf"   ___mkstr(BANKMASK(INTCON0)) "," ___mkstr(_INTCON0_GIE_POSITION) ",0"); //disable int -- 1187.5ns   (0) / 1.1875ns
                    asm("bsf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //start high  --    0.0ns   (1) / 1250.0ns
                    asm("rlcf"  ___mkstr(BANKMASK(WS_doPaint@pixel))",1,1");                                      //shift bit   --   62.5ns   (1)
                    asm("bra    $+2");                                                                 //nop*2       --  125.0ns   (1)
                    asm("btfss" ___mkstr(BANKMASK(STATUS)) "," ___mkstr(_STATUS_C_POSITION) ",0");     //test bit    --  375.0ns   (1)
                    asm("bcf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //short pulse --  437.5ns   (0/1)
                    asm("bra    $+2");                                                                 //nop*2       --  500.0ns   (0/1)
                    asm("bcf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //long pulse  --  875.0ns   (0)
                    asm("bsf"   ___mkstr(BANKMASK(INTCON0)) "," ___mkstr(_INTCON0_GIE_POSITION) ",0"); //enable int  --  937.5ns   (0)

                    asm("decfsz"   ___mkstr(BANKMASK(WS_doPaint@bitcnt))",1,1");
                asm("bra bitloop3");
//              } //bitcnt

                asm("movff"  ___mkstr(BANKMASK(INDF1)) "," ___mkstr(WS_doPaint@pixel));
                asm("movf"   ___mkstr(BANKMASK(WS_doPaint@bright))",0,1");
                asm("mulwf"  ___mkstr(BANKMASK(POSTINC1))",0");
                asm("btfss"  ___mkstr(BANKMASK(STATUS)) "," ___mkstr(_STATUS_Z_POSITION) ",0");
                asm("movff   PRODH," ___mkstr(WS_doPaint@pixel));

//              for (bitcnt=0; bitcnt<8; bitcnt++)
//              {
                asm("movlw 8");
                asm("movwf"   ___mkstr(BANKMASK(WS_doPaint@bitcnt))",1");
                asm("bitloop4:");
              
                    asm("bcf"   ___mkstr(BANKMASK(INTCON0)) "," ___mkstr(_INTCON0_GIE_POSITION) ",0"); //disable int -- 1187.5ns   (0) / 1.1875ns
                    asm("bsf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //start high  --    0.0ns   (1) / 1250.0ns
                    asm("rlcf"  ___mkstr(BANKMASK(WS_doPaint@pixel))",1,1");                                      //shift bit   --   62.5ns   (1)
                    asm("bra    $+2");                                                                 //nop*2       --  125.0ns   (1)
                    asm("btfss" ___mkstr(BANKMASK(STATUS)) "," ___mkstr(_STATUS_C_POSITION) ",0");     //test bit    --  375.0ns   (1)
                    asm("bcf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //short pulse --  437.5ns   (0/1)
                    asm("bra    $+2");                                                                 //nop*2       --  500.0ns   (0/1)
                    asm("bcf"   ___mkstr(BANKMASK(LATE)) ",1,0");                                      //long pulse  --  875.0ns   (0)
                    asm("bsf"   ___mkstr(BANKMASK(INTCON0)) "," ___mkstr(_INTCON0_GIE_POSITION) ",0"); //enable int  --  937.5ns   (0)

                asm("decfsz"   ___mkstr(BANKMASK(WS_doPaint@bitcnt))",1,1");
                asm("bra bitloop4");
//              } //bitcnt

                asm("movlw   6");
                asm("subwf"  ___mkstr(BANKMASK(FSR1L)) ",1,0");
                asm("movlw   0");
                asm("subwfb" ___mkstr(BANKMASK(FSR1H)) ",1,0");
              
            asm("decfsz"    ___mkstr(BANKMASK(WS_doPaint@pixcnt))",1,1");
            asm("bra pixloopd");
//          } //pixcnt

            asm("movlw   low(123)");
            asm("addwf"  ___mkstr(BANKMASK(FSR1L)) ",1,0");
            asm("movlw   high(123)");
            asm("addwfc" ___mkstr(BANKMASK(FSR1H)) ",1,0");

        asm("decfsz"   ___mkstr(BANKMASK(WS_doPaint@dblrow))",1,1");
        asm("bra rowloop");
//      } //dblrow
      
        asm("movlw low(936)");
        asm("subwf" ___mkstr(BANKMASK(FSR1L)) ",1,0");
        asm("movlw high(936)");
        asm("subwfb" ___mkstr(BANKMASK(FSR1H)) ",1,0");

    asm("decfsz"   ___mkstr(BANKMASK(WS_doPaint@panel))",1,1");
    asm("bra panelloop");     
//  } //panel

    ws_busy_t0 = TMR0L;      //capture current time for reset period calculation
    ws_isbusy = 1;           //signal display is busy waiting
    ws_isdirty = 0;          //and painting is complete
    PPFLAG_CAN_SLEEP = 0;    //don't sleep till reset if complete 
}
[sarcasm] C is wonderful! [\sarcasm]
 
Last edited:
Top