Changes

Jump to: navigation, search

6502

3,252 bytes added, 12:52, 8 January 2020
Created page with "Category:SPO600Category:Computer ArchitectureCategory:Assembly LanguageThe MOS Technologies 6502 process was introduced in the mid-1970s to fill the need for a aff..."
[[Category:SPO600]][[Category:Computer Architecture]][[Category:Assembly Language]]The MOS Technologies 6502 process was introduced in the mid-1970s to fill the need for a affordable general-purpose CPU. Its low cost (US$25 at introduction, less than C$0.89 now) was less than one-sixth of competing CPUs, and it had very simple circuitry requirements which made it simple and inexpensive to incorporate it into products.

== Memory ==
The 6502 (and its variants) is an 8-bit processor with a 16-bit address bus. It is therefore able to access 64 kilobytes (2<sup>16</sup> bytes). Since each 16-bit address is comprised of two 8-bit bytes, memory can be viewed as 256 pages of 256 bytes each.

Each pointer in memory is stored in two consecutive memory locations, with the lowest-value byte stored first; this is known as [[Endian#Little-Endian|Little Endian]] order. Thus, a pointer at memory location $10, which pointed to memory location $1234, would be stored like this:

Memory $10 -> $34
Memory $11 -> $12

Some pages have special, pre-defined purposes:

{|border="2"
!!Page!!Name!!Starting address!!Ending address!!Purpose
|-
||00||Zero Page||$0000||$00FF||Variables requiring fast access
|-
||01||Stack||$0100||$01FF||Values are pushed to, and pulled (popped) from, this region in first-in last-out (FIFO) order. The stack descends as it is used - more recently-pushed values are stored at lower addresses than older values. The stack wraps around, so if more than 256 bytes are pushed, the oldest values will be overwritten.
|-
||FF||Vector Table||$FF00||$FFFF||The last 6 bytes of this page contain the three 2-byte addresses. $FE contains a pointer to code which is run when an interrupt request is received; $FC contains a pointer to code which is run when the CPU is reset (including when it is first started); and $FA contains a pointer to code which is run when a non-maskable interrupt (NMI) is received.
|}

== Registers ==
There are three general-purpose registers:
* Accumulator (A) - the main register for math operations.
* X Index (X) - a register which can be used for limited math operations as well as indexed addressing modes, where an index value is added to a base address for memory operations.
* Y Index (Y) - a register similar to the X register. Some index operations may only be performed with a specific index register (X or Y, but not interchangeably).

There are also three special-purpose registers:
* Program Counter (PC) - a pointer to the currently-executing instruction in memory.
* Stack Pointer (S or SP) - a pointer to the current position in the stack
* Processor Status (P) - a collection of bits which indicate or control aspects of the processor mode and status:
** C - Carry - Used to indicate a carry or borrow during addition/subtraction
** Z - Zero flag - indicates that an operation produced a zero or equal result
** I - Interrupt disable
** D - Decimal mode - bytes are interpreted as two-digit decimal values instead of 8-bit binary values when doing math
** B - Break - Indicates a software interrupt rather than a hardware interrupt has occurred
** V - Overflow - Set when a math operation overflows a one-byte result
** S - Negative Sign - set when an operation produces a negative result

Navigation menu