6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Sep 19, 2024 1:44 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Jan 12, 2016 7:04 pm 
Offline

Joined: Sun Feb 23, 2014 2:43 am
Posts: 78
My intent here is *not* to start a processor war, but rather to discuss applying 6502 programming skills to the (8-bit) AVR architecture. Some inexpensive and accessible (DIP-packaged) versions are available which are ideal for simple projects.

The AVR instruction set seems to have been influenced in part by the 6502. Many instruction mnenomics are similar, or even identical. But from a programming standpoint, the AVR has some differences:

1. Half the branch length as 6502 (-64 to +63).
2. No real indexing modes, must use an indirect register. However after initialization, these can auto-increment or auto-decrement.
3. Modified Harvard architecture, separate instructions are required to read from RAM and ROM.
4. A more complete instruction set (but also more to remember).
5. No zero-page, but 32 registers which can be used in a similar fashion.
6. Better support for signed branches and comparisons.

Because the AVR can only act upon registers, a little more strategy is required. I tend to keep a few often-used constants in registers (like 0, 1, 255, etc). The penalty for loading an immediate from memory is only one extra cycle, but judicious use of the register file can make the code faster and more readable.

(Out of time, will try to add more later. I hope this was interesting so far.)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 13, 2016 10:06 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
I have some comments.
Quote:
The AVR instruction set seems to have been influenced in part by the 6502. Many instruction mnenomics are similar, or even identical.
Surprise, all processors work with an ALU and have opcodes for arithmetic and logic operations supported by that ALU. They all need to control program flow. So they have conditional branches, jumps, subroutine calls and returns. I can't see anything 6502 specific in the AVR instruction set but agree, that they have common roots with all central processing units ever designed.
Quote:
1. Half the branch length as 6502 (-64 to +63).
The flash ROM is addressed as 16-bit words. So the actual branch range in bytes is the same.
Quote:
2. No real indexing modes, must use an indirect register. However after initialization, these can auto-increment or auto-decrement.
Only load and store is supported, no ALU ops. IO registers have their own IN, OUT, SBI, CBI, SBIS & SBIC instructions, but are also mapped together with GPRs and RAM and can be reached by load and store to and from the RAM address space..
Quote:
3. Modified Harvard architecture, separate instructions are required to read from RAM and ROM.
More important: You cannot execute instructions from RAM!
Quote:
4. A more complete instruction set (but also more to remember).
Again, they have an ALU with similar capabilities. However, Atmel chose to supply redundant mnemonics for the same machine operation. For example: ORI is also SBR (set bits in register), CLR is an EOR self, status bits can be set and branched on by bit # or function...
Immediate ops have their own mnemonic instead of an operand modifier (#). They occupy most of the 16-bit instructions: immediate operand = 8 bits, 16 registers addressable = 4 bits and of the remaining 4 bits for the ALU operation 5 of the 16 codes (ANDI/CBR, CPI, LDI, ORI/SBR, SUBI) are used. No room is left for EORI or ADDI.
Quote:
5. No zero-page, but 32 registers which can be used in a similar fashion.
They are true accumulators and support all ALU operations. Most ops accu to accu and immediate to accu take only 1 cycle!

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 14, 2016 5:04 pm 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
It looks like the 6502 has more in common with the STM8 CPU, including an accumulator and X/Y registers. May be a fun processor for those familiar with 6502.

http://www.st.com/st-web-ui/static/acti ... 161709.pdf


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 18, 2016 6:00 pm 
Offline

Joined: Sun Feb 23, 2014 2:43 am
Posts: 78
This was probably a half-baked idea for a thread, my apologies.

The point I was trying to make was that my experience with the 6502 transferred over to this processor very well, because the syntax was similar enough and easy to remember.

A friend gave me an STM8 dev board years ago but I never got around to learning it. Will have to do that soon.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: