XXXoYYY

From Esolang
Jump to navigation Jump to search

XXXoYYY (no official pronunciation given) is an esolang created by User:Dtp09. XXXoYYY programs follow a strict syntax of every instruction being a single character opcode, followed by a three character operand, hence it's title. Every program must be in 7-bit ASCII, and every instruction must be contiguous.

Memory

XXXoYYY utilizes 128^3 (2,097,152) 32-bit signed integers of addressable memory, along with a single "register", which is also a 32 bit signed integer. Memory addresses can be thought of either as a direct address (a three digit ASCII code), or a numeric address (a number). Numeric addresses out of bounds are mapped to valid addresses in bounds via modding the numeric address by 128^3.

Nearly every value in memory is initialized to zero on the first read or write. The exception to this is values in direct addresses that are purely numeric (000-999), which are initialized to the base ten number given by their direct address. These addresses are still writable.

Direct Addressing

Direct addressing is preformed with instructions that read the operand as a memory address. Every accessible memory address can be directly addressed in an operand, albeit some require non-printing ASCII characters to do so.

Indirect Addressing

Two opcodes are reserved for indirect reading and writing instructions. These instructions will read the value at the direct address given by the opcode as a numeric address. The instruction will then read or write the value at that numeric address. Another opcode is reserved for an instruction that retrieves the numeric address of a direct address and writing it to the register.

Input/Output

IO is handled via memory mapped registers at direct addresses NIO (Numeric Input Output) and AIO (ASCII Input Output). Reading from AIO will interrupt execution to prompt the user for an ASCII character and passing it's 7-bit character code (-1 for no character given), and reading from NIO will prompt the user for a 32-bit integer. Writing to AIO will push a 7-bit ASCII character to the output, ignoring all but the 7 lowest bits of the value being written, and writing to NIO will push a 32-bit integer to the output followed by an ASCII space.

Instructions

Every instruction can utilize the register's value, as well as the operand succeeding it (interpreted as either a jump label or memory address) to preform an operation, updating the register as necessary.

Opcode Description New Register Value
Invalid No operation. Not updated
. Directly load a value in memory into register. Value at direct address
, Indirectly load a value in memory into register. Value at indirect address
: Directly write the value in register to memory. Not Updated
; Indirectly write the value in register to memory. Not Updated
# Retrieve the numeric address of the direct address. Numeric address of direct address
+ Adds value at direct address to register. register + value at direct address
- Subtracts value at direct address from register. register - value at direct address
* Multiplies value at direct address with register. register * value at direct address
/ Divides register by value at direct address, flooring quotient. floor(register / value at direct address)
% Modulates register by value at direct address. register % value at direct address
& Bitwise AND register with value at direct address. register AND value at direct address
Pipe Bitwise OR register with value at direct address. register OR value at direct address
! Bitwise XOR register with value at direct address. register XOR value at direct address
= Compare register to value at direct address for equivalency. 1 or 0 for true or false
> Compare register to value at direct address for greaterness. 1 or 0 for true or false
< Compare register to value at direct address for lesserness. 1 or 0 for true or false
? Skip the next instruction if register is zero or negative. Value at direct address (after evaluation)
( Jump to instruction after next occurance of operand in program. Not Updated
) Jump to instruction after previous occurance of operand in program. Not Updated
[ Directly load a value in memory into register. Value at direct address
] Jump to instruction after previous occurance of opcode ] if register is greater than zero Not Updated
~ Halt execution. Not Updated

Comments

Due to the nature of undefined/invalid opcodes being no-op, comments can be written without interfering with execution, as long as the comment doesn't contain valid opcodes in places where opcodes are read.

.AIO    Read user input
:AIO 

This code snippet first executes a direct load from AIO, followed by opcodes Space, "R", Space, "r", and "p", all invalid, before executing a direct write to AIO. Extra spaces are inserted to pad the comment's length to a multiple of four characters, including the newline character, to ensure that the opcode following the newline is read as an opcode and not an operand.

Examples

Truth-machine

.NIO:num=000?num:NIO=001?001(inf~inf:NIO)inf