Cornflower (PCD)

From Esolang
Jump to navigation Jump to search

Cornflower machine is an esoteric P-code format (EISC) invented by Jan "Manna5" Mleczko in December 2021. It has memory consisting of 256 registers, each one byte long. Every instruction consists of exatcty three bytes, instructions are taken from a binary file (usually width PCD filename extension) and executed one by one. First byte of instruction is the operation code: there are 8 different operations. What operation is performed depends of the 3 least significant bits of that byte. Operation table is shown below:

Operation table
Code Mnemonic Description
000 MOV Move single data byte from one register to another.
001 ADD Unsigned addition in memory.
010 SUB Unsigned subtraction in memory.
011 CMP Compare two values in memory, skip next instruction if not equal.
100 JMP Jump to the instruction number ... in program file.
101 DAT Initialize specified register with an immediate value.
110 BUS Communicate using the bus.
111 NOP Do nothing.

Last two instruction bytes are operation parameters. In instructions MOV, ADD and SUB first parameter byte (second instruction byte) is the destination register, and second parameter byte is the source register. Instructions CMP and DAT also use the same parameter format. In the BUS instruction, first parameter is port number and second parameter is source/destination register (depending on the port is input or output). JMP instruction has a single 16 bit little-endian parameter. In NOP instructions parameter bytes must occur, but parameter values are ignored. I have implemented an assembler and an emulator linked below. Sorry for my English.

Assembler: https://rextester.com/VXDW49540

Emulator: https://rextester.com/CTT84813