Skip to content

4 ‐ Instructions and Codes

QualityCroissant edited this page Jun 25, 2025 · 18 revisions

For this section, the mnemonics and abstractions used will be those implemented in Fox Assembly. However, a different implementation of an assembly language for this architecture could handle things differently. Such alternative implementations, again, would be welcomed. Additionally, all opcodes or operands being 64 bits in-size leaves room for extensions and modifications to the architecture, and thus the number of instructions will not change in the future, to encourage such endeavours.

As to how opcodes, operands, and data are stored in the binary format used by Fox, everything is, again, of a size matching the 64 bit word-size of the architecture overall. Each opcode, operand, or other datum are stored in a space of 64 bits each. Operands simply follow the opcode in the next arbitrary number of 64 bit slots, for the amount required for that opcode. For example, the instruction a+, which requires no operands, would only take up one 64 bit slot. However, the instruction mv mdr acc would use three 64 bit slots, one for mv, the next for mdr, and the next for acc.

Instructions

Opcode Mnemonic Operands Description
0 pl value register Place a raw value into register
1 mv register1 register2 Move the contents of register1 into register2
2 st Store MDR at MAR in the selected MCH
3 ld Load into MDR the data at MAR in the selected MCH
4 jm address Set CEA to address
5 js address Set CEA to address if Accumulator is set (non-zero)
6 jc address Set CEA to address if Accumulator is clear (zero)
7 a+ Add the contents of Data to Accumulator and store the result in Accumulator
8 a- Subtract the contents of Data from Accumulator and store the result in Accumulator
9 a! Invert the bits of the Accumulator
10 ai Increment the Accumulator by 1
11 ad Decrement the Accumulator by 1
12 a* Multiply the contents of Accumulator by Data and store the result in Accumulator
13 a/ Divide the Accumulator by Data and store the result in Accumulator
14 a& Logically AND the bits of Accumulator with the bits of Data and store the result in Accumulator
15 a| Logically OR the bits of Accumulator with the bits of Data and store the result in Accumulator
16 a^ Logically XOR the bits of Accumulator with the bits of Data and store the result in Accumulator
17 al Left shift bits of Accumulator by 1, Data amount of times
18 ar Right shift bits of Accumulator by 1, Data amount of times
19 gt Set the Accumulator to non-zero if it is greater than Data, otherwise set it to zero
20 lt Set the Accumulator to non-zero if it is less than Data, otherwise set it to zero
21 ge Set the Accumulator to non-zero if it is greater than or equal to Data, otherwise set it to zero
22 le Set the Accumulator to non-zero if it is less than or equal to Data, otherwise set it to zero
23 eq Set the Accumulator to non-zero if it is equal to Data, otherwise set it to zero
24 ne Set the Accumulator to non-zero if it is not equal to Data, otherwise set it to zero
25 cl address Jump to address after pushing CEA onto the Callstack
26 rt Jump to the address on the Callstack at CSP, then pop this address off of the Callstack
27 fi Terminate program execution and initiate the shutdown process (should be included at the end of all programs that are expected to reach the end of their execution)

Codes

Memory Channel Mnemonic Description
0 mem Main Memory
1 inp Input
2 out Output
3 cst Callstack

Registers gp0-gp7 are implemented as of v0.8-beta:

Register Mnemonic Description
0 mch Memory Channel
1 mar Memory Address Register
2 mdr Memory Data Register
3 acc Accumulator
4 dat Data
5 cea Current Execution Address
6 csp Callstack Pointer
7 gp0 General Purpose Register 0
8 gp1 General Purpose Register 1
9 gp2 General Purpose Register 2
10 gp3 General Purpose Register 3
11 gp4 General Purpose Register 4
12 gp5 General Purpose Register 5
13 gp6 General Purpose Register 6
14 gp7 General Purpose Register 7

Memory-Channel-Specific Addresses

If Input or Output is the selected Memory Channel, the possible values for MAR mean different things.

Value of MAR Area Written-to or Read-from when Input or Output is the current Memory Channel
0 Standard I/O
1 Secondary Storage
2 Screen Buffer (implemented as of v0.4-alpha)
3 Keyboard (implemented as of v0.8-beta)
4+ Currently unimplemented

Fox Assembly-Specific Syntaxes

Syntax Meaning
label= ... Replace all instances of label with ... for the entirety of the source document
label:
label: ...
Replace all instances of label with the address of the data that it is placed before for the entirety of the source document
[text]s Store the bytes of text from this point downwards, each byte at the lowest byte of their own 64 bit cell
[number]d Store the 64-bit base-10 (decimal) number at this point
[number]x Store the 64-bit base-16 (hexadecimal) number at this point
[number]o Store the 64-bit base-8 (octal) number at this point
[number]b Store the 64-bit base-2 (binary) number at this point
; ... Do not process anything between the ; and a newline or end-of-file

Things to watch out for

Fox Assembly uses whitespace to separate tokens. Any amount of whitespace can be used, but it must be included. For example, zero= [0]b is valid syntax, but zero=[0]b is not, and nor is zero =[0]b, nor zero = [0]b.

At this point in time, hexadecimal numbers must use uppercase letters and not lowercase letters. This will be changed in-future, but for now something like [5D]x is valid whilst [5d]x is not. This is amended as of v0.3-alpha!

Clone this wiki locally