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

Reading T7

Hi

The code generated when I read the value of sfr T7 is as follows.

   178:                         start_time = T7 ;
00005C98 F2FE50F0  MOV      R14,DPP3:0x3050
   179:                         _nop_() ;

I would like it to be
MOV   R14,T7

What compiler options do I need to set to generate this ?

Cheers

Elliot

  • Hi Elliot,

    Despite the fact that the C166 compiler generates quite good code, in some situations when you look at the generated code you can see some very basic optimizations it doesn't do, like in this case. I can think of a couple more examples as well. It can be annoying but it can't be avoided.
    I think that the solution to this problem is to not look at the generated code as often to avoid disappointment. When optimization must be done, it can be done with assembly language.
    Of course, it is possible that in this particular case I missed something and there is a settings that makes the compiler generate better code, but I doubt that.

    - mike

  • I wrote the following simple program:

    #include <REG167.H>
    
    unsigned int main (void)
    {
    unsigned int start_time;
    start_time = T7;
    
    return (start_time);
    }

    When I compiled it, I got the following:

                 ; FUNCTION main (BEGIN  RMASK = @0x4010)
                                               ; SOURCE LINE # 3
                                               ; SOURCE LINE # 4
                                               ; SOURCE LINE # 6
    0000 F2F450F0      MOV       R4,T7
    ;---- Variable 'start_time' assigned to Register 'R4' ----
                                               ; SOURCE LINE # 8
                                               ; SOURCE LINE # 9
    0004 CB00          RET
                 ; FUNCTION main (END    RMASK = @0x4010)

    This looks like what you want. And, the code generated matches EXACTLY what you show except for a different register being used (R4 vs R14). I guess the difference is in the disassembly.

    Accessing SFRs requires an OPcode (16-bits) and an address (16-bits). The SFRs are located in the last 16K page of the first 64K of memory. This area is accessed using DPP3. That's why you see the DPP3 and the SFR offset in the disassembly.

    As far as optimization goes, I don't think there is a shorter instruction available to read T7. If there is, maybe you could point it out?

    Jon

  • Hi Jon,

    You are absolutely right. I must admit, I made a mistake. I got confused at first because in the C166 instruction set there is the instruction MOV Rn,Rm: F0nm. But the 4-bit addressing mode can't be used for T7, so this instruction wouldn't work here.
    But I would like to point out a different inefficiency in C166. Try compiling this code:

    unsigned long l;
    unsigned int i;
    void main(void)
    {
        i = (unsigned int)(l >> 16) + 1;
    }
    the compiler generates:
    0000 F2F50200 R    MOV       R5,l+02H
    0004 F045          MOV       R4,R5   ; <- unnecessary
    0006 0841          ADD       R4,#01H
    0008 F6F40400 R    MOV       i,R4
    000C CB00          RET       
    Looks like the optimizer fails to eliminate unnecessary loading into temporary storage, which would seem a very basic type of optimization.

    - mike