Gyo is a register machine with 16 instructions.
Gyo was designed as an educational system foundational computing concepts. The computer has 16 registers, 16 opcodes and 256 memory addresses. The gyo assembler syntax supports =constants
and :labels
. The computer and assembler are written in less than 400 lines of ANSI C code.

Instructions
Each instruction uses 4-bits for the operation, 4-bits for the addressing mode and 8 bits for the address. The instructions are written directly into the RAM and read from the memory, the program can be modified as it is running. Programs are loaded directly into memory to create procedural self-modifiable programs.
0x0 | BRK | Break |
0x1 | JMP | Jump to position in memory |
0x2 | JCA | Jump to position in memory, when carryflag |
0x3 | JZE | Jump to position in memory, when not zeroflag |
0x4 | PEK | Read status |
0x5 | POK | Write status |
0x6 | GET | Store in register |
0x7 | PUT | Store in memory |
0x8 | ADD | Add value to register, set carryflag when overflow |
0x9 | SUB | Substract value from register, set carryflag when overflow |
0xA | EQU | Compare register with value, set zeroflag when equal |
0xB | LES | Compare register with value, set zeroflag when less than |
0xC | AND | Bitwise AND operator |
0xD | XOR | Bitwise XOR operator |
0xE | ROL | Bitwise rotate left |
0xF | ROR | Bitwise rotate right |
There are 4 principal addressing modes:
instruction | result |
---|---|
EQU #00 | the raw value |
EQU $EF | the value at address #EF in memory |
EQU [e] | the value of the 15th register |
EQU {e} | the value at the address of the 15th register |
Registers are used by reading and writing to the status using a combination of bitwise operators, to quickly select the 3rd register and set all flags to 0, use POK #20
.
Assembler
The assembler syntax supports :label, ~const and =var.
; comment =rate #01 ; defines a constant ; program :label GET $02 PUT #03 BRK
Conditional
The following example demonstrate how to do a conditional jump.
GET #EF ; load #EF in register EQU [1] ; set zeroflag if r0 is equal to r1 JZE there ; if equal, goto :there :here PUT #10 ; write in memory at #10 BRK :there PUT #20 ; write in memory at #20 BRK
Loop
The following example demonstrate how to do a basic loop.
:loop ADD #01 EQU #0f JZE end JMP loop :end BRK
Status Register
The status register is distributed as follows, it shares the same byte as the register selector. The halt flag is used by the BRK instruction is stops the cpu, the zero flag is used for logic instructions, the carry flag is set when an instruction carries over the 8bit range and the traps flag is set when the pointer should be sent to the traps location(in IO operations).
T C Z H | | | +---- Halt | | +------ Zero | +-------- Carry +---------- Traps
IO
To begin IO mode, activate the traps flag with POK #08
.
POK #08 ; Set traps flag ON GET ; Read character from stdin PUT [0] ; Write character to stdout POK #00 ; Set traps flag OFF
Hello World
POK #20 ; select r2 GET hello ; store location of :hello :loop POK #00 ; select r0 GET [1] ; get value of r1 ADD [2] ; add value of r2 POK #08 ; set traps flag PUT {0} ; stdout value of memory[r0] POK #10 ; select r1, remove traps ADD #01 ; add 1 EQU #06 ; set zeroflag if == 6 JZE end ; end if true JMP loop ; repeat :end BRK :hello #48 #65 #6C #6C #6F #0A

14R10
— Gyo Release