??? 01/22/08 12:42 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#149826 - Dangerous Responding to: ???'s previous message |
Paul Blakey said:
which could be hand optimized to
temp = ~(mainoff); temp++; _asm mov _TL2,r2 mov _TH2,r3 _endasm;but its less portable and only saves two commands... This is not less portable, it is very dangerous. Any change to your code might make the compiler use different registers for the temporary storage. Andy Neil said:
BTW: some 8051 compilers can handle TH and TL as a single 16-bit SFR - I don't know SDCC, so you'll have to check the Manuals to see if it can and, if so, how.
If supported, this is likely to be the most efficient way - but, of course, not portable. OTOH: Frieder Ferlemann said:
You might want to try one of these:
#include <compiler.h> SFR16(TMR2, 0xCC); unsigned int mainoff = 5000; void main () { TMR2 = ~(mainoff - 1); } Using the header file <compiler.h> you can use 16-bit sfr constructs without worrying about which compiler is actually used. The SFR16 macro expands to the appropriate code for any compiler that supports 16-bit sfr combinations. In your case you could use: temp = ~(mainoff); temp++; TMR2 = temp;Maarten |
Topic | Author | Date |
SDCC, copying integer in ASM | 01/01/70 00:00 | |
Shift-and-mask, or union | 01/01/70 00:00 | |
I used asm tag and the rr command but.... | 01/01/70 00:00 | |
Your question | 01/01/70 00:00 | |
Portable unions | 01/01/70 00:00 | |
Less non-portable? | 01/01/70 00:00 | |
Less non-portable | 01/01/70 00:00 | |
portable, schmortable | 01/01/70 00:00 | |
Disagree! | 01/01/70 00:00 | |
how portable? | 01/01/70 00:00 | |
emphasis | 01/01/70 00:00 | |
Real world portable![]() | 01/01/70 00:00 | |
using - does not give the same result | 01/01/70 00:00 | |
try this | 01/01/70 00:00 | |
You are exceeeding 2 byte signed integer limits | 01/01/70 00:00 | |
Fighting the tools | 01/01/70 00:00 | |
Thanks all. | 01/01/70 00:00 | |
Dangerous | 01/01/70 00:00 | |
Very important warning! | 01/01/70 00:00 |