5. Opcode implementation
Thursday 30th July 2026
I've started implementing each opcode, low hanging fruit first (the easy ones):
//region immediate opcode methods
//... todo ...
//endregion
//region standard opcode methods
private fun inc(isShort: Boolean) {
sourceStack.push(sourceStack.pop(isShort) + 1, isShort)
}
private fun pop(isShort: Boolean) {
sourceStack.pop(isShort)
}
//... todo ... all the rest...
private fun add(isShort: Boolean) {
val b = sourceStack.pop(isShort)
val a = sourceStack.pop(isShort)
sourceStack.push(a + b, isShort)
}
private fun sub(isShort: Boolean) {
val b = sourceStack.pop(isShort)
val a = sourceStack.pop(isShort)
sourceStack.push(a - b, isShort)
}
private fun mul(isShort: Boolean) {
val b = sourceStack.pop(isShort)
val a = sourceStack.pop(isShort)
sourceStack.push(a * b, isShort)
}
private fun div(isShort: Boolean) {
val b = sourceStack.pop(isShort)
val a = sourceStack.pop(isShort)
sourceStack.push(if (b == 0) 0 else a / b, isShort)
}
private fun and(isShort: Boolean) {
val b = sourceStack.pop(isShort)
val a = sourceStack.pop(isShort)
sourceStack.push(a and b, isShort)
}
private fun ora(isShort: Boolean) {
val b = sourceStack.pop(isShort)
val a = sourceStack.pop(isShort)
sourceStack.push(a or b, isShort)
}
private fun eor(isShort: Boolean) {
val b = sourceStack.pop(isShort)
val a = sourceStack.pop(isShort)
sourceStack.push(a xor b, isShort)
}
//endregion