Re: Moving from 8051 to AVR

Ulf Samuelsson wrote:
Getting rid of global variables is good programming practices
but the 8051 will force you to use this costing extra time and
making the C code more unreadable.
I'm lost. How do the extra opcode features of the C51, like
direct memory access, and Boolean operators, make code LESS
readable ?

Direct memory access means that you are using up the decoding space that should be used for registers.
It is not "extra" opcode features, it is waste of decoding space.

That's not really a great argument - it would be simple enough to drop a single register (say, r0) and make that refer to "direct memory" with the address given in the next instruction word. That would also have simplified a number of instructions - for example, the "LDS Rd, k" instruction would now be implemented simply "MOV Rd, R0, k".

If you want to argue that this would make a larger core, or increase the critical path lengths of the decoder, or cause problems for the pipelining logic (a more common reason for RISC architectures' omission of direct memory access instructions), that's fine. But there would have been no problem doing a little re-arranging of the opcode space to fit the addressing mode in.

Lack of registers means that local variables cannot be optimized into registers.
This means you are forced to use global variables.
I.E: you are making the code harder to read and thus less maintainable.

If you have more SRAM than you need which is often the case in 0.18u processes
then the use boolean operators makes code less portable/readable.
Writing a boolean variable is more expensive than writing a byte variable
since you have to do a read-modify write - OR go to a much more expensive SRAM implementation.