Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
instruction_encoding [2021/03/11 10:33] – pulkomandy | 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 ===== | ||
" | " | ||
- | |||
- | FIXME BREAK is probably somewhere here, document it. | ||
==== 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 | + | |
+ | 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 ==== | ||
^Instruction^Opcode0^Operand A^Opcode1^6-bit Immediate | ^Instruction^Opcode0^Operand A^Opcode1^6-bit Immediate | ||
^ CALL | F | ? | ^ CALL | F | ? | ||
- | ^ GOTO | F | ? | 2 | CS: value | | PC value | | + | ^ GOTO | F | 7 | 2 | CS: value | | PC value | |
The target address is formed by the immediate6 value (for CS:) and another word after the instruction (for PC) | The target address is formed by the immediate6 value (for CS:) and another word after the instruction (for PC) | ||
Line 38: | Line 56: | ||
^Instruction | ^Instruction | ||
- | ^ INT OFF | + | ^ INT OFF |
- | ^ INT IRQ | + | ^ INT IRQ |
- | ^ INT FIQ | + | ^ INT FIQ |
- | ^ INT IRQ, | + | ^ INT IRQ, |
- | ^ FIR_MOV ON | F | 0 | 5 | 04 | | + | ^ FIR_MOV ON | F | ? | 5 | 04 | |
- | ^ FIR_MOV OFF | + | ^ FIR_MOV OFF |
| | | | ||
- | ^ IRQ OFF | + | ^ IRQ OFF |
- | ^ IRQ ON | F | 0 | 5 | 09 | | + | ^ IRQ ON | F | ? | 5 | 09 | |
| | | | ||
- | ^ FIQ OFF | + | ^ FIQ OFF |
| | | | ||
- | ^ FIQ ON | F | 0 | 5 | 0E | | + | ^ FIQ ON | F | ? | 5 | 0E | |
| | | | ||
- | ^ NOP | F | 0 | 5 | | + | ^ BREAK | F | ? | 5 | |
FIXME probably other instructions (FRACTION, ...) fit in here | FIXME probably other instructions (FRACTION, ...) fit in here | ||
Line 60: | 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 |
| | | | ||
- | Opcode1 indicates the jump direction, and can be 0 (jump back) or 1 (jump forward) | + | Opcode1 indicates the jump direction, and can be 0 (jump forward) or 1 (jump backward). The offset is counted from the opcode // |
===== 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 |
- | ^ OR | A | Op. A |Addr Mode|Param | + | ^ RETF | 9 |5 (SR) |
- | ^ AND | + | ^ RETI | 9 |5 (SR) |
- | ^ TEST | C | Op. A |Addr Mode|Param | + | ^ OR | A |Op. A |Addr Mode|Param |
- | ^ ST | D | Op. A |Addr Mode|Param | + | ^ AND |
- | ^ PUSH | D | Op. A | + | ^ TEST | C |Op. A |Addr Mode|Param |
- | | | + | ^ ST | D |Op. A |Addr Mode|Param |
- | | | + | ^ PUSH | D |Last reg -1 |
+ | | | ||
+ | | | ||
+ | |||
+ | Depending on opcode1, various addressing modes can be used: | ||
+ | |||
+ | ^Addressing mode ^Opcode0^Operand A^Opcode1 | ||
+ | ^%% [BP+Imm6] | ||
+ | ^%% #Imm6 %%| ALU op| Op. A | 1 | ||
+ | | Special (POP, PUSH) | | ||
+ | ^%% [Rs] %%| ALU op| Op. A | 3 | 0 | Rs | | ||
+ | ^%% [Rs--] | ||
+ | ^%% [Rs++] | ||
+ | ^%% [++Rs] | ||
+ | ^%% D: | ||
+ | ^%% D: | ||
+ | ^%% D: | ||
+ | ^%% D: | ||
+ | ^%% Rs %%| ALU op| Op. A | 4 | 0 | Rs | | ||
+ | ^%% # | ||
+ | ^%% From [Addr16] %%| ALU op| Op. A | 4 | 2 | Rs* | |16-bit address in next word, Rs is first operand| | ||
+ | ^%% To [Addr16] | ||
+ | ^%% Rs ASR shift %%| ALU op| Op. A | 4 | 4 + (shift - 1) | Rs | | ||
+ | ^%% Rs LSL shift %%| ALU op| Op. A | 5 | shift - 1 | Rs | | ||
+ | ^%% Rs LSR shift %%| ALU op| Op. A | 5 | 4 + (shift - 1) | Rs | | ||
+ | ^%% Rs ROL shift %%| ALU op| Op. A | 6 | shift - 1 | Rs | | ||
+ | ^%% Rs ROR shift %%| ALU op| Op. A | 6 | 4 + (shift - 1) | Rs | | ||
+ | ^%% [Addr6] | ||
- | For these instructions, | + | The instructions using Imm16 or Addr16 are 3-operand |
- | * 0: [BP+Imm6] | + | '' |
- | * 1: #Imm6 | + | |
- | * 2: special functions: push, pop, reti and retf | + | |
- | * 3: [Rs] | + | |
- | * 4: addressing depends on opN | + | |
- | * 5: Rs LSL/LSR OpN | + | |
- | * 6: Rs ROL/ROR OpN | + | |
- | * 7: [Imm6] | + | |
- | In a POP instruction: | + | naken_asm syntax: |
- | * OperandA+1 is the first popped register (it is not possible to push R0/SP) | + | '' |
- | * OperandN is the number of registers to push | + | |
- | * OperandB is the register to use as a stack pointer | + | |
- | RETF is a special case of POP with opA=5, opN=2, opB=0 (restores R6 and R7) | + | All other forms are 2-operand: operand A is always |
- | RETI is a special case of POP with opA=5, opN=3, opB=0 (restores R6, R7, and an extra special register containing interrupt flags) | + | The LD operation uses operand A only as a target. |
- | In a PUSH instruction: | + | The ST operation uses the second source operand (Rs, address, ...) as the target, and operand A (always |
- | * OperandA+1 is the last pushed register | + | Other operations can use both forms, so the "From [Addr16]" |
- | * OperandN is the number of registers to push | + | |
- | * OperandB is the register to use as a stack pointer | + | |
- | When opcode1 is 3, operandN defines incrementation and use of DS: | + | '' |
- | * 0: [Rs] | + | and the " |
- | * 1: [Rs--] | + | |
- | * 2: [Rs++] | + | |
- | * 3: [++Rs] | + | |
- | * 4: DS:[Rs] | + | |
- | * 5: DS:[Rs--] | + | |
- | * 6: DS:[Rs++] | + | |
- | * 7: DS:[++Rs] | + | |
- | When opcode1 is 4, operandN defines more addressing modes: | + | '' |
- | * 0: Rs | + | (so in this case the register encoded in OPA is used as a source, not a destination). |
- | * 1: 16-bit immediate value | + | |
- | * 2: Load from memory address | + | |
- | * 3: Store to memory address | + | |
- | * 4: Rs ASR 1 | + | |
- | * 5: Rs ASR 2 | + | |
- | * 6: Rs ASR 3 | + | |
- | * 7: Rs ASR 4 | + | |
- | When opcode1 is 5 or 6, operandN MSB defines the shift direction, | + | The LD and ST operations with the 16-bit addressing mode ignore |