; This simple program defines custom instructions. ; QUICK NOTE: Defining an already existing instruction as a custom instruction will overwrite it. ; Another thing is that trying to use a custom instruction before it is defined will not work. custom! CINS 0x9999 reg int mem ; This custom instruction has opcode 0x9999, and it expects a register, an integer, and a memory address. custom! CINS 0x9991 reg mem ; You can also define variants. custom! CINS 0x9992 ; You can also do instructions without arguments. LOAD r0, ; Load the opcode of instruction CINS into register 0. (This works on normal instructions too.) LOAD r1, ; Load the opcode of instruction CINS (other variant) into register 1. LOAD r2, ; I think you understand now. ASSERT r0, 0x9999 ; Just asserting that the opcode in register 0 is correct. ASSERT r1, 0x9991 ; Just asserting that the opcode in register 1 is correct. ASSERT r2, 0x9992 ; You get the point. CINS r1, 0x4F, &0x0078F2 ; Call our new CINS instruction! CINS r15, &0xC0FFEE ; Calling the other variant as well. CINS ; Calling the variant that has no arguments. ; Now, let's see what happens with pre-existing instructions: CMP r0, r1 ; Old CMP instruction. custom! CMP 0x8888 reg reg ; Overwriting CMP (reg, reg). (The other CMP instruction variants are left alone.) CMP r0, r1 ; New CMP instruction.