Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
instruction_encoding [2021/04/14 17:02] – [Jump instructions] simer | instruction_encoding [2024/07/01 13:29] (current) – [Multiplication] simer | ||
---|---|---|---|
Line 7: | Line 7: | ||
^Contents|Opcode0|Operand A|Opcode1|6-bit Immediate | ^Contents|Opcode0|Operand A|Opcode1|6-bit Immediate | ||
+ | ===== Summary ===== | ||
+ | |||
+ | ^Opcode 0\1 ^ 0 ^ 1 ^ 2 ^ 3 ^ 4 ^ 5 ^ 6 ^ 7 ^ | ||
+ | ^Addressing mode|[BP+Imm6]|# | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | ^ | ||
+ | |||
+ | * Instructions in bold: uses the addressing mode listed on the first line | ||
+ | * Instructions in italics: only if operand A (destination register) is PC | ||
===== Special instructions ===== | ===== Special instructions ===== | ||
Line 13: | Line 36: | ||
==== Multiplication ==== | ==== Multiplication ==== | ||
- | ^Instruction | + | ^Instruction |
- | ^MUL (unsigned)| | + | ^MAC (unsigned*signed) | F | Op.A |
- | ^MUL (signed) | + | ^MAC (signed*signed) |
- | + | ^MUL (unsigned*signed) | F | Op.A | |
- | FIXME | + | ^MUL (signed*signed) |
- | | + | |
- | * document MAC instructions | + | |
- | * document unsigned-to-unsigned vs signed-to-unsigned instructions | + | |
- | * division instructions may have a similar format | + | |
Note: Operand A and Operand B cannot be 0, 6 or 7 (it is not possible to multiply SP, SR or PC with something). | Note: Operand A and Operand B cannot be 0, 6 or 7 (it is not possible to multiply SP, SR or PC with something). | ||
+ | They also can not be 3 or 4 in MAC (MR is used for intermediate results). If the size of the MAC | ||
+ | operation is exactly 16, it will be encoded as N=0. | ||
==== CALL and GOTO ==== | ==== CALL and GOTO ==== | ||
Line 58: | Line 78: | ||
Jump instructions are identified by Operand A = 7 (makes sense, because they change the PC which is register 7) | Jump instructions are identified by Operand A = 7 (makes sense, because they change the PC which is register 7) | ||
- | ^Instruction | + | ^Instruction |
- | ^ JCC, JB, JNAE | 0 | | + | ^ JB, JNAE, JCC | 0 | |
- | ^ JCS, JNB, JAE | 1 | | + | ^ JAE, JNB, JCS | 1 | |
- | ^ JSC, JGE, JNL | 2 | | + | ^ JGE, JNL, JSC | 2 | |
- | ^ JSS, JNGE, JL | 3 | | + | ^ JL, JNGE, JSS | 3 | |
- | ^ JNE, JNZ | 4 | | + | ^ JNE, JNZ | 4 | |
- | ^ JE, JZ | 5 | | + | ^ JE, JZ | 5 | |
- | ^ JPL | + | ^ JPL |
- | ^ JMI | + | ^ JMI |
- | ^ JBE, JNA | 8 | | + | ^ JBE, JNA | 8 | |
- | ^ JNBE, JA | 9 | | + | ^ JA, JNBE |
- | ^ JLE, JNG | A | | + | ^ JLE, JNG | A | |
- | ^ JNLE, JG | B | | + | ^ JG, JNLE |
- | ^ JVC | + | ^ JVC |
- | ^ JVS | + | ^ JVS |
- | ^ JMP | + | ^ JMP |
| | | | ||
Line 80: | Line 100: | ||
===== ALU instructions ===== | ===== ALU instructions ===== | ||
- | ^Instruction | + | ^Instruction |
- | ^ ADD | + | ^ ADD |
- | ^ ADC | + | ^ ADC |
- | ^ SUB | + | ^ SUB |
- | ^ SBC | + | ^ SBC |
- | ^ CMP | + | ^ CMP |
- | | | + | | |
- | ^ NEG | + | ^ NEG |
- | | | + | | |
- | ^ XOR | + | ^ XOR |
- | ^ LD | 9 | Op. A |Addr Mode|Param | + | ^ LD | 9 |Op. A |Addr Mode|Param |
- | ^ POP | + | ^ POP |
- | ^ RETF | 9 | 5 (SR) | 2 | 2 (SR, PC) | 0 (SP) | | + | ^ RETF | 9 |5 (SR) |
- | ^ RETI | 9 | 5 (SR) | 2 | 3 (SR, PC, FR) | 0 (SP) | | + | ^ RETI | 9 |5 (SR) |
- | ^ OR | A | Op. A |Addr Mode|Param | + | ^ OR | A |Op. A |Addr Mode|Param |
- | ^ AND | + | ^ AND |
- | ^ TEST | C | Op. A |Addr Mode|Param | + | ^ TEST | C |Op. A |Addr Mode|Param |
- | ^ ST | D | Op. A |Addr Mode|Param | + | ^ ST | D |Op. A |Addr Mode|Param |
- | ^ PUSH | D |Last reg -1| 2 |Register count| Stack pointer reg | | + | ^ PUSH | D |Last reg -1 | 2 |Register count| Stack pointer reg | |
- | | | + | | |
- | | | + | | |
Depending on opcode1, various addressing modes can be used: | Depending on opcode1, various addressing modes can be used: | ||
- | ^Addressing mode^Opcode0^Operand A^Opcode1 | + | ^Addressing mode ^Opcode0^Operand A^Opcode1 |
^%% [BP+Imm6] | ^%% [BP+Imm6] | ||
^%% #Imm6 %%| ALU op| Op. A | 1 | ^%% #Imm6 %%| ALU op| Op. A | 1 | ||
Line 117: | Line 137: | ||
^%% D: | ^%% D: | ||
^%% Rs %%| ALU op| Op. A | 4 | 0 | Rs | | ^%% Rs %%| ALU op| Op. A | 4 | 0 | Rs | | ||
- | ^%% # | + | ^%% # |
- | ^%% From [Addr16] %%| ALU op| Op. A | 4 | 2 | Rs | |16-bit address in next word| | + | ^%% From [Addr16] %%| ALU op| Op. A | 4 | 2 | Rs* | |16-bit address in next word, Rs is first operand| |
- | ^%% To [Addr16] | + | ^%% To [Addr16] |
^%% Rs ASR shift %%| ALU op| Op. A | 4 | 4 + (shift - 1) | Rs | | ^%% Rs ASR shift %%| ALU op| Op. A | 4 | 4 + (shift - 1) | Rs | | ||
^%% Rs LSL shift %%| ALU op| Op. A | 5 | shift - 1 | Rs | | ^%% Rs LSL shift %%| ALU op| Op. A | 5 | shift - 1 | Rs | | ||
Line 131: | Line 151: | ||
'' | '' | ||
- | smasm syntax: | + | naken_asm |
'' | '' | ||
Line 140: | Line 160: | ||
The ST operation uses the second source operand (Rs, address, ...) as the target, and operand A (always a register) as the source. | The ST operation uses the second source operand (Rs, address, ...) as the target, and operand A (always a register) as the source. | ||
+ | |||
+ | Other operations can use both forms, so the "From [Addr16]" | ||
+ | |||
+ | '' | ||
+ | |||
+ | and the "To [Addr16]" | ||
+ | |||
+ | '' | ||
+ | |||
+ | (so in this case the register encoded in OPA is used as a source, not a destination). | ||
+ | |||
+ | The LD and ST operations with the 16-bit addressing mode ignore the value of Rs, they use only Ra and the 16-bit value. |