6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Sep 29, 2024 10:18 am

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sun Feb 23, 2014 1:55 pm 
Offline

Joined: Sun Feb 23, 2014 1:45 pm
Posts: 12
Every guide about 6502 assembly talks about things called A, X and Y, but none of them explain what they are, where they are used, etc. It's odd that in the very beginning parts these are introduced but never explained.


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 23, 2014 2:35 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10940
Location: England
That's a very fundamental question! They are registers, byte-sized storage locations on-chip. To operate on data in memory, you typically have to load it into one of the registers then perform your work and eventually write out the result to memory. Or if not memory, then I/O devices. There are some operations which operate directly on memory, so you can increment a memory location without using any registers, but if you want to add two numbers, you'll find you need to use A, the accumulator.

See this diagram:
Code:
                         TRANSFER OPERATIONS
                         -------------------

 +-----------------------------------------------------------------+
 |                             MEMORY                              |
 |                           $0000-$FFFF                           |
 +-----------------------------------------------------------------+
      ^    |                   ^    |                   ^    |
      |    |                   |    |                   |    |
     STX  LDX                 STA  LDA                 STY  LDY
      |    |                   |    |                   |    |
      |    V                   |    V                   |    V
 +--------------+         +--------------+         +---------------+
 |              |---TXA-->|              |<--TYA---|               |
 |  X-REGISTER  |         |  A-REGISTER  |         |  Y-REGISTER   |
 |              |<--TAX---|              |---TAY-->|       +       |
 +--------------+         +--------------+         +---------------+
      |    ^                   ^    |
      |    |                   |    |
     TXS  TSX                 PLA  PHA
      |    |                   |    |
      V    |                   |    V
 +--------------+         +--------------+         +---------------+
 |              |         |              |---PLP-->|               |
 |  S-REGISTER  |         |    STACK     |         |  P-REGISTER   |
 |              |         | $0100-$01FF  |<--PHP---|   NV*BDIZC    |
 +--------------+         +--------------+         +---------------+


                           OTHER OPERATIONS
                           ----------------

 +-----------------------------------------------------------------+
 |               A-REGISTER    X-REGISTER    Y-REGISTER    MEMORY  |
 |-----------------------------------------------------------------|
 |  Arithmetic:  ADC           INX           INY           INC     |
 |               SBC           DEX           DEY           DEC     |
 |                                                                 |
 |  Logical:     AND           ---           ---           BIT     |
 |               ORA           ---           ---           ---     |
 |               EOR           ---           ---           ---     |
 |                                                                 |
 |  Shift:       ASL           ---           ---           ASL     |
 |               LSR           ---           ---           LSR     |
 |               ROL           ---           ---           ROL     |
 |               ROR           ---           ---           ROR     |
 |                                                                 |
 |  Compare:     CMP           CPX           CPY           ---     |
 +-----------------------------------------------------------------+

 +----------------------------------------------------+
 |  Status:      SET           CLEAR         BRANCH   |
 |----------------------------------------------------|
 |       CARRY   SEC           CLC           BCC, BCS |
 |    OVERFLOW   ---           CLV           BVC, BVS |
 |     DECIMAL   SED           CLD           -------- |
 |   INTERRUPT   SEI           CLI           -------- |
 |        ZERO   ---           ---           BEQ, BNE |
 |       MINUS   ---           ---           BPL, BMI |
 +----------------------------------------------------+

    Jump:     JMP, JSR   -------------------------------------------
                         6502 Programming Model, Bob Sander-Cederlof
    Return:   RTS, RTI          Apple Assembly Line, May 1981
                         http://txbobsc.com/aal/1981/aal8105.html#a4
    Other:    NOP, BRK   -------------------------------------------


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 23, 2014 3:57 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
The top section of http://6502.org/tutorials/ should help. The book "Programming the 65816, including the 6502, 65C02 and 65802" there is excellent, and I'm sure other ones listed there are too, although I'm not familiar with all of them.

"A" is short for "accumulator" and is kind of the central register. X and Y have indexing functions. Other registers in the 6502 that the programmer deals with directly are P (processor status), PC (program counter), and S (stack pointer).

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 23, 2014 6:42 pm 
Offline

Joined: Sun Feb 23, 2014 1:45 pm
Posts: 12
Few more questions:
1. What's the difference between the accumulator (A) register and the indexing function (X and Y) registers (in what kind of situations they are used)?
2. What are the S and P registers and the stack used?
3. How is the Memory are divided for specific actions (like drawing sprites)?
4. Is there a complete colour chart made for the available colours for 6502 and their data values?


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 23, 2014 8:05 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
Most of those questions can only be answered in the context of a particular implementation, like C64, Apple, Atari, Atom, KIM, NES, VIC20 etc. All of those systems use a variant of the 6502, but have a diverse collection of support hardware, and that support hardware determines how the memory, display, keyboard and other I/O are to be utilized.

Mike


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 23, 2014 8:19 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
A is where the logic and arithmetic functions start and end. X & Y are for indexing; for example, the instruction LDA $14F3,X will load A (the accumulator) with the value read from the address that is the sum of $14F3 and the contents of X; so for example if X had 5 in it, then A would be loaded with the contents of address $14F3+5, or $14F8. Indexing can be used with indirects also.

S (the Stack pointer) is like an index register to stack operations which are in page 1, ie, from addresses $0100 to $01FF. Stack operations automatically increment and decrement S.

P (Processor status) register has status bits (or flags) telling if an arithmetic or logic function resulted in a negative result (N flag), result of zero (Z flag), or that oVerflow caused the sign bit to be wrong (V flag), or resulted in a Carry or a borrow (C flag), or affect the processor's operation like the Decimal (D) flag, or Interrupt-disable (I) flag, or tell if an interrupt was caused by a software Break instruction (B flag).

Most of the memory range can be used in many ways, although there are a few requirements, given in the memory map requirements page of the 6502 primer, at http://wilsonminesco.com/6502primer/MemMapReqs.html .

It's far too much to explain in detail in a forum post, but hopefully this will get your imagination going. The books at the link above will explain it all. I'm in the process of writing a treatise on stacks, but the basics will be covered just fine in the books. [Edit: It's up, at http://wilsonminesco.com/stacks/index.html .]

As for the number of colors and so on, that does not really depend on the processor, but the attached video hardware.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 23, 2014 8:32 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8406
Location: Midwestern USA
Baka94 wrote:
Few more questions:
1. What's the difference between the accumulator (A) register and the indexing function (X and Y) registers (in what kind of situations they are used)?
2. What are the S and P registers and the stack used?
3. How is the Memory are divided for specific actions (like drawing sprites)?
4. Is there a complete colour chart made for the available colours for 6502 and their data values?

I (and no doubt others) highly recommend that you read the available literature before posing questions of this type. We are more than happy to help someone starting out with the 6502 assembly language, but like to see that that individual has made a modicum of effort to seek relevant material.

Garth Wilson already suggested reading the 6502/65C02/65C816 programming manual, which covers the 6502 family from top to bottom, and goes from the most basic levels (What is a byte?) to fairly advanced programming concepts. I also recommend that you read Richard Mansfield's Machine language for Beginners, which starts from scratch, making only small assumptions about the reader's knowledge, meaning it doesn't explain basic computer concepts. Mansfield's book was the jumping off point for countless 6502 programmers in the 1980s (many of whom went on to become very fluent in 6502 assembly language) and remains valid to this day.

If you get the urge to build a 6502-powered device you should look at the resources here and also check out Garth's website for lots of helpful hardware info.

Incidentally, questions 3 and 4 are machine-specific. The 6502 knows nothing about colors, sprites, sound, etc. Such features are implemented in other devices.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 26, 2014 3:16 am 
Offline

Joined: Wed Jun 26, 2013 9:06 pm
Posts: 56
Baka94 wrote:
Few more questions:
1. What's the difference between the accumulator (A) register and the indexing function (X and Y) registers (in what kind of situations they are used)?
2. What are the S and P registers and the stack used?
3. How is the Memory are divided for specific actions (like drawing sprites)?
4. Is there a complete colour chart made for the available colours for 6502 and their data values?


When you mentioned about the color chart it made me thinking, was there ever a computer system with the CPU having its own graphics output? I'm now imagining a CPU with a scan line buffer built in, and blitting instructions.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 26, 2014 6:02 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8406
Location: Midwestern USA
Aaendi wrote:
Baka94 wrote:
4. Is there a complete colour chart made for the available colours for 6502 and their data values?

When you mentioned about the color chart it made me thinking, was there ever a computer system with the CPU having its own graphics output? I'm now imagining a CPU with a scan line buffer built in, and blitting instructions.

Well, the graphics processors (GPU) used in modern video cards are capable of "blitting" and other tasks that offload a lot of the grunt work of managing the video display from the microprocessor (MPU). In such scenarios, the MPU issues relatively terse commands to the GPU and the latter works independently of the MPU to generate and manipulate the the image.

The 8563 and 8568 video display controllers, which were used in the Commodore 128, were 6502 bus-compatible devices with some primitive intelligence, such as block fill and copy functions.

However, to answer your question, I'm not aware of any system in which the MPU itself drives the video display. Someone else here might know differently.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 26, 2014 6:24 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10940
Location: England
Parallax' propeller chip has (minimal) video hardware on-chip. See for example http://www.rayslogic.com/propeller/propeller.htm and http://learn.parallax.com/propeller-c-s ... xt-display

Cheers
Ed


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 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: