Special variables: Difference between revisions

Content deleted Content added
Puppydrum64 (talk | contribs)
Puppydrum64 (talk | contribs)
m →‎{{header|6502 Assembly}}: explained direct page
Line 9:
=={{header|6502 Assembly}}==
The first 256 bytes of the CPU's address space are collectively known as "zero page RAM" and are common to all 6502 computers (except the custom 6502-based Hu6280 used in the PC Engine/TurboGrafx16.) This section of RAM is faster to load from, as the instructions that use it only take one byte to represent the memory address rather than two. On some implementations, certain zero-page RAM addresses are special, such as address $00 on Commodore 64 (which supposedly controls bank switching) and address $FF on Easy6502 (which contains the last keyboard input). In addition to loading faster, only the zero page can used indexed indirect addressing modes (the only exception being <code>JMP</code>, which CANNOT jump indirectly using zero page unless you pad it with a high byte of 00.)
 
The 16-bit 65816 and the Motorola 6809 (which are very similar to the 6502) call the zero page the "direct page" because it can be relocated on those systems. They have a dedicated register which tells the CPU where the direct page actually is. Like on the 6502, it's only 256 bytes in size. This allows the programmer to improve their program's performance by moving the direct page to wherever the majority of the loading will be taking place. Your code may cause problems if you load from the "wrong" direct page, however, so be careful!
 
 
In addition, the last 6 bytes of the address space contain the NMI, Reset, and IRQ vectors, respectively. These values are pointers to functions, which get called when the associated pins are pulled low. In the case of the NMI and IRQ lines, the CPU will automatically push the program counter and the flags, and effectively execute <code>JMP ($FFFA)</code> for NMI and effectively <code>JMP ($FFFE)</code> for IRQ. A reset doesn't push the flags or program counter.