This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to write code to help complier store variable into register??

Hi all

I try to use Generate Assembler SRC file to see the assembler code ,I found the complier is smart
enough to stroe variable into register sometimes ,
but sometimes is strange. I try to complier same code
twice times ,one time, it will sotre into register ,
one time is not,Why??

The first time ,I got this

?XD?int0_hander?MAIN
SEGMENT XDATA OVERLAYABLE

RSEG ?XD?_int0_hander?MAIN
?int_hander?BYTE:

msgsts?040: DS 1

intsts?041: DS 1

The second time,I got this

msgsts?040 is stroe in R2 register

intsts?041 is also stroe in R2 register

Another example,I have a interrupt handler function
it just read clear the interrupt status register

void irc_int_hander(void)
{
 intsts = ptr_reg[IRC_INT_STS];

dma_task_scheduler(0,0,0);

}

why "insts" will not store into register ,there is R2,R6 are free, but others more complex code can do this well.

any comment is welcome

Best Regards

Parents
  • Thanks all

    I just for fun to know why complier wiil sometimes smart ,and sometimes is not??

    I think for complier ,it must follow some rules
    to complier our code,right??

    So if I know the rules to mark code small and fast
    why not to do it??

    Code1

     uchar onoff = ptr_reg[y]
     ptr_reg[x] = onoff;
    

    Code2

     uchar onoff = ptr_reg[y]
     ptr_reg[x] |= onoff;
    

    The code2 just change = to |= ,but the code size and speed is fast then code1!! Best regards

Reply
  • Thanks all

    I just for fun to know why complier wiil sometimes smart ,and sometimes is not??

    I think for complier ,it must follow some rules
    to complier our code,right??

    So if I know the rules to mark code small and fast
    why not to do it??

    Code1

     uchar onoff = ptr_reg[y]
     ptr_reg[x] = onoff;
    

    Code2

     uchar onoff = ptr_reg[y]
     ptr_reg[x] |= onoff;
    

    The code2 just change = to |= ,but the code size and speed is fast then code1!! Best regards

Children