Special variables: Difference between revisions

→‎{{header|6502 Assembly}}: removed hardware vector table since they're constant at runtime.
m (→‎{{header|MIPS Assembly}}: removed $zero as it's not really a variable since its value cannot be changed.)
(→‎{{header|6502 Assembly}}: removed hardware vector table since they're constant at runtime.)
Line 14:
 
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.
 
<lang 6502asm>;DEFINING INTERRUPT VECTORS ON THE NES
org $FFFA
dw #### ;address of your NMI handler goes here (you can use labels for each of these for your convenience)
dw #### ;address of your Reset handler goes here
dw #### ;address of your IRQ handler goes here.</lang>
 
Depending on the hardware, programming the NMI, Reset, and IRQ routines may not be your responsibility. On the NES, nothing is done for you and you'll have to create both the routines for each of these labels and store their memory locations at the end of the address space.
Home computers like the Commodore 64 have the interrupt vector table and routines pre-loaded as part of the firmware, which is why you don't have to define them on programs you write for those. However, sometimes you can often indirectly change what the IRQ does using system calls to pass a pointer to a new interrupt handler.
 
=={{header|Ada}}==
1,489

edits