Special variables: Difference between revisions

added 6502 and z80
(added 6502 and z80)
Line 7:
List the special variables used within the language.
<br><br>
=={{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.)
 
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.
 
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}}==
Line 2,145 ⟶ 2,152:
My name is John and my parent's name is Fred.
</pre>
=={{header|Z80 Assembly}}==
It's somewhat debatable whether processor registers count as "variables," since they don't have a location in the address space but their contents can change. Excluding those for now, there are a few memory locations that have special meaning:
 
The following memory locations can be called as functions using the <code>RST</code> instructions. Each appears to take a byte as an operand, but in fact there are only 8 different "operands" and each is hardcoded in, which means that only one byte is needed to describe both the <code>RST</code> and the destination byte. Unfortunately, there is very little room for code in these areas, since each is only '''8 bytes long!''' Most of the time you'll put a jump to the actual routine you want to execute in these areas. The last one, <code>RST 38</code>, may allow more room for code depending on the system.
 
* &0000 - called with RST 00
* &0008 - called with RST 08
* &0010 - called with RST 10
* &0018 - called with RST 18
* &0020 - called with RST 20
* &0028 - called with RST 28
* &0030 - called with RST 30
* &0038 - called with RST 38
 
The memory location &0066 is special because it contains the NMI routine. NMI stands for "Non-Maskable Interrupt" and is a hardware interrupt that can't be stopped by a <code>DI</code> command. When an NMI occurs, the CPU will save the program counter on the stack and jump to &0066, and execute from there. The <code>RETN</code> instruction is used to return back to the main program. Usually an <code>ORG </code> directive is the easiest way to guarantee that your code will begin at the correct address for NMI. Since you can't predict exactly what state your program will be in when an NMI happens, it's important that the NMI routine uses either the stack or the exchange commands to preserve the register state at the start and restores it before returning. Otherwise, your NMI could ruin whatever your program was doing at the time.
 
Depending on the hardware, programming the NMI routine may not actually be your responsibility. It's usually only required when programming for a ROM-cartridge game console like the Sega Master System. On home computers, the NMI routine at &0066 is typically built into the firmware by the manufacturer and cannot be changed; however that routine will often contain a jump to another memory location that you can change indirectly using system calls and parameter passing.
 
 
<lang z80>org &0066
 
NMI_HANDLER: ;this label is optional, the CPU doesn't need it to know how to jump here.
retn ;in this example, the NMI routine will immediately return without doing anything.</lang>
 
 
 
 
 
 
=={{header|zkl}}==
<lang zkl>__DATE__, __DEBUG__, __FILE__, __LINE__, __NAME__, __TIME__</lang>
As in the C preprocessor. Some (like __DEBUG__) can be changed, others (like __LINE__, __TIME__) are constants.
 
 
=={{header|ZX Spectrum Basic}}==
Line 2,229 ⟶ 2,265:
 
{{omit from|GUISS|Does not have any variables at all}}
{{omit from|6502 Assembly|Existence of special variables depends entirely on the implementation}}
{{omit from|68000 Assembly|Existence of special variables depends entirely on the implementation}}
 
{{omit from|Z80 Assembly|Existence of special variables depends entirely on the implementation}}
{{omit from|8086 Assembly|Existence of special variables depends entirely on the implementation}}
{{omit from|x86 Assembly|Existence of special variables depends entirely on the implementation}}
1,489

edits