QWEN Instructions
Qwen has 26 instructions. Instructions are all two bytes long and stored big-endian. The instructions are listed below, in hexadecimal.
Symbols:
-NNNN: Address
-NN: 8-bit constant
-N: 4-bit constant
-X and Y: 4-bit register identifier
-PC: Program Counter
-I: 16-bit register
-RN: One of the 16 variables. N can be 0 to F (Hexadecimal)
Opcode | Type | C Pseudo | Explanation |
---|---|---|---|
0x0000 | Display | clear(); | Clears the display. |
0x0001 | Flow | return; | Returns from a subroutine. Sets the PC to address at the top of the stack, then subtracts 1 from the stack pointer (SP). |
0x0002 | Flow | goto NNNN; | Jumps to address NNNN(High byte from R0 register and low byte from R1 register). Sets the PC to NNNN. |
0x0003 | Flow | *(0xNNNN)(); |
Calls subroutine at NNNN(High byte from R0 register and low byte from R1 register). Increments the stack pointer, then puts
the current PC on the top of the stack. The PC is then set to NNNN. |
0x1XNN | Assign | RX = NN; | Sets RX to NN. |
0x2XY0 | Assign | RX = RY; | Sets RX to the value of RY. |
0x2NN1 | Assign | *((R0<<8) | (R1)) = NN; | Set (R0<<8) | R1 memory location to NN. |
0x31XY | Bitwise Operation | RX = RX | RY; | Sets RX to RX or RY (Bitwise OR Operation). |
0x32XY | Bitwise Operation | RX = RX & RY; | Sets RX to RX and RY (Bitwise AND Operation). |
0x33XY | Bitwise Operation | RX = RX ^ RY; | Sets RX to RX xor RY (Bitwise XOR Operation). |
0x34X1 | Bitwise Operation | RX >>= 1; | Stores the least significant bit of RX in RF and then shifts RX to the right by 1. |
0x34X2 | Bitwise Operation | RX <<= 1; | Stores the most significant bit of RX in RY and then shifts RX to the left by 1. |
0x4XNN | Math Operation | RX += NN; | Adds NN to RX (Carry flag is not changed). |
0x51XY | Math Operation | RX += RY; | Adds RY to RX. RF is set to 1 when there's carry, and to 0 when there isn't. |
0x52XY | Math Operation | RX -= RY; | RY is subtracted from RX. RF is set to 0 when there's a borrow, and 1 when there isn't. |
0x6XNN | Condition | if (RX==NN); | Skip the next instruction if RX equals NN. |
0x7XNN | Condition | if (RX!=NN); | Skip the next instruction if RX doesn't equal NN. |
0x8XY0 | Condition | if (RX==RY); | Skip the next instruction if RX qeuals RY. |
0x9X01 | Key Operation | if (key()==RX); | Skip the next instruction if the key stored in RX is pressed . |
0xA000 | Memory | RI += NNNN; | Adds NNNN(High byte from R0 register and low byte from R1 register) to RI |
0xBX00 | Memory | RI = sprite_address[RX]; | Sets RI to the location of the sprite for the character code in RX. Characters A-Z (Non-case-sensitive), 0-9, +, -, *, /. |
0xC00X | Random Operation | RX = rand(); | Sets RX to a random number(0-255). |
0xDXY0 | Display | Draw(RX,RY); |
Draw a sprite at coordinate(RX, RY) that has a 8x8 pixels. Each row of 8 pixels is read as 4-bit-coded starting from
memory location RI. |
0xEX00 | Key Operation | RX = get_key(); | A key press is awaited, and then stored in RX. |
0xFNN0 | Timer | delay(NN); | Delay NN milliseconds. |
0xF0N1 | Sound | play_sound(N); | Play sound N(see sound chart) for 0.5 milliseconds. |