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_() ;
MOV R14,T7
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); }
; 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)
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; }
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