Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
instruction_encoding [2021/03/11 11:00] pulkomandyinstruction_encoding [2023/12/18 12:45] – [ALU instructions] pulkomandy
Line 11: Line 11:
 "Special" instructions are identified by Opcode0 = 0xF "Special" instructions are identified by Opcode0 = 0xF
  
-Opcode1 determines the instruction:+==== Multiplication ====
  
-  * 0: MUL +^Instruction           ^Opcode0^Operand A^Opcode1       ^OPN         ^Operand B^ 
-  1: CALL +^MAC (unsigned*signed) |  F    |  Op.A    + (N ≥ 8) |   N & 7    |  Op.B   | 
-  2: GOTO +^MAC (signed*signed)    F    |  Op.A    + (N ≥ 8) |   N & 7    |  Op.B   | 
-  * 3: ??? +^MUL (unsigned*signed) |  F    |  Op.A    0                    |  Op.B   | 
-  4: MULS +^MUL (signed*signed)    F    |  Op.A    4                    |  Op.B   |
-  * 5: INT, NOP +
-  6: ??? +
-  * 7: ???+
  
-TODOBREAK is probably somewhere here.+NoteOperand 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 stored as N=0. 
 +==== CALL and GOTO ====
  
-==== MUL and MULS ==== +^Instruction^Opcode0^Operand A^Opcode1^6-bit Immediate         | ^ Second word ^ 
- +^ CALL      |  F    |   ?     |      CS: value             | |   PC value  | 
-With OperandN = and OperandA != 7 (other cases are not documented yet?) +GOTO       F    |        2    |  CS: value             | |   PC value  |
- +
-OperandA and OperandB are multiplied together. +
- +
-==== CALL and GOTO ====+
  
 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 36: Line 32:
 ==== Interrupts ==== ==== Interrupts ====
  
-OperandA must be 0.+^Instruction    ^Opcode0^Operand A^Opcode1^6-bit Immediate 
 +^ INT OFF        F    |   ?      5    |  00             | 
 +^ INT IRQ        F    |   ?      5    |  01             | 
 +^ INT FIQ        F    |   ?      5    |  02             | 
 +^ INT IRQ,FIQ    F    |   ?      5    |  03             | 
 +^ FIR_MOV ON    |  F    |   ?      5    |  04             | 
 +^ FIR_MOV OFF    F    |   ?      5    |  05             | 
 +|                                                   | 
 +^ IRQ OFF        F    |   ?      5    |  08             | 
 +^ IRQ ON        |  F    |   ?      5    |  09             | 
 +|                                                   | 
 +^ FIQ OFF        F    |   ?      5    |  0C             | 
 +|                                                   | 
 +^ FIQ ON        |  F    |   ?      5    |  0E             | 
 +|                                                   | 
 +^ BREAK          F    |   ?      5    |  20             |
  
-The operation depends on the Immediate6 value: +FIXME probably other instructions (FRACTION, ...) fit in here
- +
-  * 00: INT OFF +
-  * 01: INT IRQ +
-  * 02: INT FIQ +
-  * 03: INT FIQ,IRQ +
-  * 04: FIR_MOV ON +
-  * 05: FIR_MOV OFF +
-  * 06: ??? +
-  * 07: ??? +
-  * 08: IRQ OFF +
-  * 09: IRQ ON +
-  * 0A: ??? +
-  * 0B: ??? +
-  * 0C: FIQ OFF +
-  * 0D: ??? +
-  * 0E: FIQ ON +
-  * 0F: ??? +
-  * 25: NOP +
-  * All other values: ???+
  
 ===== Jump instructions ===== ===== Jump instructions =====
  
-Jump instructions are identified by Operand A = 0+Jump instructions are identified by Operand A = 7 (makes sense, because they change the PC which is register 7)
  
-The type of jump depends on Opcode0:+^Instruction    ^Opcode0^Operand A^Opcode1  ^6-bit Immediate  ^Condition   | 
 +^ JB, JNAE, JCC |  0    |       |Direction| Jump offset     | C = 0      | 
 +^ JAE, JNB, JCS |  1    |       |Direction| Jump offset     | C = 1      | 
 +^ JGE, JNL, JSC |  2    |       |Direction| Jump offset     | S = 0      | 
 +^ JL, JNGE, JSS |  3    |       |Direction| Jump offset     | S = 1      | 
 +^ JNE, JNZ      |  4    |       |Direction| Jump offset     | Z = 0      | 
 +^ JE, JZ        |  5    |       |Direction| Jump offset     | Z = 1      | 
 +^ JPL            6    |       |Direction| Jump offset     | N = 0      | 
 +^ JMI            7    |       |Direction| Jump offset     | N = 1      | 
 +^ JBE, JNA      |  8    |       |Direction| Jump offset     | !(Z=0&C=1) | 
 +^ JA, JNBE      |  9    |       |Direction| Jump offset     | Z=0 & C=1  | 
 +^ JLE, JNG      |  A    |       |Direction| Jump offset     | !(Z=0&S=0) | 
 +^ JG, JNLE      |  B    |       |Direction| Jump offset     | Z=0 & S=0  | 
 +^ JVC            C    |       |Direction| Jump offset     | N = S      | 
 +^ JVS            D    |       |Direction| Jump offset     | N != S     | 
 +^ JMP            E    |       |Direction| Jump offset     | Always     | 
 +|                F    |       | Reserved for special instructions ||
  
-  * 0: JCC JB JNAE +Opcode1 indicates the jump directionand can be (jump forward) or (jump backward). The offset is counted from the opcode //following// the jump instruction, so an offset of 0 would jump to the next instruction (basically NOP) while a offset of -1 (1 backwards) would be an infinite loop and a offset of (+1) would skip a single instruction.
-  * 1: JCS JNB JAE +
-  * 2: JSC JGE JNL +
-  * 3: JSS JNGE JL +
-  * 4: JNE JNZ +
-  * 5: JE JZ +
-  * 6: JPL +
-  * 7: JMI +
-  * 8: JBE JNA +
-  * 9: JNBE JA +
-  * A: JLE JNG +
-  * B: JNLE JG +
-  * C: JVC +
-  * D: JVS +
-  * E: JMP +
-  * F: Reserved for special instructions (see above) +
- +
-In jump instructionsOpcode1 is to jump forward, and to jump back. The offset is stored as 6-bit immediate.+
  
 ===== ALU instructions ===== ===== ALU instructions =====
  
-Opcode0 determines the instruction type, as follows: +^Instruction    ^Opcode0^Operand A    ^Opcode1  ^OPN           ^Operand B^ 
- +^ ADD               |Op. A        |Addr Mode|Param         | Op. B   | 
-  0: ADD +^ ADC               |Op. A        |Addr Mode|Param         | Op. B   | 
-  1: ADC +^ SUB               |Op. A        |Addr Mode|Param         | Op. B   | 
-  2: SUB +^ SBC               |Op. A        |Addr Mode|Param         | Op. B   | 
-  3: SBC +^ CMP               |Op. A        |Addr Mode|Param         | Op. B   | 
-  4: CMP +|                                                      |         | 
-  * 5: ??? +^ NEG               |Op. A        |Addr Mode|Param         | Op. B   | 
-  6: NEG +|                                                      |         | 
-  * 7: ??? +^ XOR               |Op. A        |Addr Mode|Param         | Op. B   | 
-  8: XOR +^ LD            |     |Op. A        |Addr Mode|Param         | Op. B   | 
-  9: LD +^ POP            9    |First reg - 1|2        |Register count| Stack pointer reg | 
-  * A: OR +^ RETF          |  9    |5 (SR)       |2        |2 (SR, PC)    | 0 (SP)  | 
-  BAND +^ RETI          |  9    |5 (SR)       |2        |3 (SR, PC, FR)| 0 (SP)  | 
-  C: TEST +^ OR            |  A    |Op. A        |Addr Mode|Param         | Op.   | 
-  D: ST +AND           |  B    |Op. A        |Addr Mode|Param         | Op. B   | 
-  * E: ??? +^ TEST          |     |Op. A        |Addr Mode|Param         | Op. B   | 
-  F: Special instructions, see above +^ ST            |     |Op. A        |Addr Mode|Param         | Op. B   | 
- +^ PUSH          |  D    |Last reg -1  |  2      |Register count| Stack pointer reg  | 
-TODO: I don't know what the TEST instruction does differently from CMP?+|                                                      |         | 
 +|                    Reserved for special instructions   ||||
  
-For these instructionsOpcode1 defines the addressing mode:+Depending on opcode1various addressing modes can be used:
  
-  * 0: [BP+Imm6] +^Addressing mode    ^Opcode0^Operand A^Opcode1  ^OPN               ^Operand B^ ^Notes       ^ 
-  * 1: #Imm6 +^%% [BP+Imm6]     %%| ALU op|  Op. A  | 0        6-bit immediate          || | Op. A ≠ PC | 
-  2: special functionspush, pop, reti and retf +^%% #Imm6         %%| ALU op|  Op. A  | 1        6-bit immediate          || | Op. A ≠ PC | 
-  3: [Rs] +| Special (POP, PUSH) |             | 2                        |         | 
-  4: addressing depends on opN +^%% [Rs]          %%| ALU op|  Op. A  | 3       | 0                | Rs      | 
-  * 5: Rs LSL/LSR OpN +^%% [Rs--]        %%| ALU op|  Op. A  | 3       | 1                | Rs      | 
-  6Rs ROL/ROR OpN +^%% [Rs++]        %%| ALU op|  Op. A  | 3                      | Rs      | 
-  * 7: [Imm6]+^%% [++Rs]        %%| ALU op|  Op. A  | 3       | 3                | Rs      | 
 +^%% D:[Rs]        %%| ALU op|  Op. A  | 3       | 4                | Rs      | 
 +^%% D:[Rs--]      %%| ALU op|  Op. A  | 3       | 5                | Rs      | 
 +^%% D:[Rs++]      %%| ALU op|  Op. A  |       | 6                | Rs      | 
 +^%% D:[++Rs]      %%| ALU op|  Op. A  | 3       | 7                | Rs      | 
 +^%% Rs            %%| ALU op|  Op. A  |       | 0                | Rs      | 
 +^%% #Imm16        %%| ALU op|  Op. A  | 4       | 1                | Rs      | |16-bit immediate in next word| 
 +^%% From [Addr16] %%| ALU op|  Op. A  | 4       | 2                | Rs      | |16-bit address in next word| 
 +^%% To [Addr16]   %%| ALU op|  Op. A  | 4       | 3                | Rs      | |16-bit address in next word| 
 +^%% 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  |       | shift - 1        | Rs      | 
 +^%% Rs ROR shift  %%| ALU op|  Op. A  | 6       | 4 + (shift - 1)  | Rs      | 
 +^%% [Addr6      %%| ALU op|  Op. A  | 7        6-bit address            ||
  
-When opcode1 is 2:+The instructions using Imm16 or Addr16 are 3-operand instructions, for example:
  
-  * LD becomes POP +''R3 = R2 + Imm16''
-  * ST becomes PUSH +
-  * Other values of opcode0 are not allowed+
  
-In a POP instruction:+naken_asm syntax:
  
-  * OperandA+1 is the first popped register (it is not possible to push R0/SP) +''ADD R3, R2, #Imm16''
-  * 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 register and used as both source and destination.
  
-RETI is 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 target.
  
-In PUSH instruction:+The ST operation uses the second source operand (Rs, address, ...) as the target, and operand A (always register) as the source.
  
-  * OperandA+1 is the last pushed register +Other operations can use both forms, so the "From [Addr16]" would be something like this:
-  * 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:+''R3 = R2 + [Addr16]''
  
-  * 0: [Rs] +and the "To [Addr16]" corresponds to:
-  * 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:+''[Addr16] = R2 + R3''
  
-  * 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, and the 2 other bits define the amount of shifting (1 to 4 bits)+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.
instruction_encoding.txt · Last modified: 2023/12/31 16:49 by pulkomandy
CC Attribution 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0