Doreq
Doreq is a OISC interpreter of the same named instruction.
Basic
Each doreq instruction has 8 memory address operands.
A B C X Y Z J K
If the value at memory address C is positive then value of memory address A and B will be added together, otherwise B will be subtracted from A. The result of the previous operation will be assigned to memory address X, value at memory address B will be passed onto memory address Y and C will have its sign inverted and then passed onto memory address Z. If the value at memory address X is equal to 0 then jump to address J otherwise jump to address K. If the address to jump is equal to -1 then halt. Because each value has its own address the instructions are 8 addresses long.
Examples
This example will count down from 10 to 0 and then halt.
8, 9, 10, 11, 12, 13, 14, 15, 10, 1, -1, 8, 9, 16, -1, 0, 99
The first instruction from address 0 to 7, checks the value of address 10. The value is -1 so address 11 will be assisgned the result of address 9 subtracted from address 8, address 12 will be assigned the value of address 9 and address 13 will be assigned the value of address 10 but sign inverted which is +1. The value at address 8 is not equal to 0 so a jump will be made to address 15 which has a value of 0 so back to address 0.
The example below is an extension of the one above and results in the sum of 9+8+7+6+5+4+3+2+1 being assigned to memory address 17
8, 9, 10, 11, 12, 13, 14, 15, 10, 1, -1, 8, 9, 16, -1, 24, 99, 0, 1, 98, 0, 0, 0, 0, 17, 8, 18, 24, 25, 19, 14, 20
An Interpreter
This is an interpreter for Doreq written in Javascript
var memory = [] var program_counter = 0 var A, B, C, X, Y, Z, J, K while (program_counter >= 0) { A = memory[memory[program_counter]] B = memory[memory[program_counter+1]] C = memory[memory[program_counter+2]] X = memory[memory[program_counter+3]] Y = memory[memory[program_counter+4]] Z = memory[memory[program_counter+5]] J = memory[memory[program_counter+6]] K = memory[memory[program_counter+7]] if (C >= 0) { memory[X] = A+B } else { memory[X] = A-B } memory[Y] = B memory[Z] = -C if (memory[X] === 0) { program_counter = J } else { program_counter = K } }
This next interpreter is 200% more woke and uses ternary operators to rekt the one above and is absolutely useful as an example!
var memory = [] var program_counter = 0 while (program_counter >= 0) { memory[memory[memory[program_counter+3]]] = (memory[memory[program_counter+2]] >= 0) ? memory[memory[program_counter]]+memory[memory[program_counter+1]] : memory[memory[program_counter]]-memory[memory[program_counter+1]] memory[memory[memory[program_counter+4]]] = memory[memory[program_counter+1]] memory[memory[memory[program_counter+5]]] = -memory[memory[program_counter+2]] program_counter = (memory[memory[memory[program_counter+3]]] === 0) ? memory[memory[program_counter+6]] : memory[memory[program_counter+7]] }