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
instruction_encoding [2021/03/11 13:14] – [ALU instructions] pulkomandyinstruction_encoding [2023/12/31 16:49] (current) – [ALU instructions] pulkomandy
Line 10: Line 10:
  
 "Special" instructions are identified by Opcode0 = 0xF "Special" instructions are identified by Opcode0 = 0xF
- 
-FIXME BREAK is probably somewhere here, document it. 
  
 ==== Multiplication ==== ==== Multiplication ====
  
-^Instruction   ^Opcode0^Operand A^Opcode1^OPN         ^Operand B^ +^Instruction           ^Opcode0^Operand A^Opcode1       ^OPN         ^Operand B^ 
-^MUL (unsigned)|  F    |  Op.A   |       1        |  Op.B   | +^MAC (unsigned*signed) |  F    |  Op.A   |  2 + (N ≥ 8) |   N & 7     Op.B   
-^MUL (signed)  |  F    |  Op.A   |  4    |          |  Op.B   | +^MAC (signed*signed)    F    |  Op.A    6 + (N ≥ 8) |   N & 7    |  Op.B   | 
- +^MUL (unsigned*signed) |  F    |  Op.A   |  0           |          |  Op.B   | 
-FIXME +^MUL (signed*signed)    F    |  Op.  |  4                    |  Op.B   |
-  document possible values for OPN +
-  * document MAC instructions +
-  * document unsigned-to-unsigned vs signed-to-unsigned instructions +
-  * division instructions may have a similar format +
- +
-Note: Operand cannot be 7 (it is not possible to multiply 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 stored as N=0.
 ==== CALL and GOTO ==== ==== CALL and GOTO ====
  
 ^Instruction^Opcode0^Operand A^Opcode1^6-bit Immediate         | ^ Second word ^ ^Instruction^Opcode0^Operand A^Opcode1^6-bit Immediate         | ^ Second word ^
 ^ CALL      |  F    |   ?      1    |  CS: value             | |   PC value  | ^ CALL      |  F    |   ?      1    |  CS: value             | |   PC value  |
-^ GOTO      |  F    |       |  2    |  CS: value             | |   PC value  |+^ GOTO      |  F    |       |  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 33:
  
 ^Instruction    ^Opcode0^Operand A^Opcode1^6-bit Immediate  | ^Instruction    ^Opcode0^Operand A^Opcode1^6-bit Immediate  |
-^ INT OFF        F    |       |  5    |  00             | +^ INT OFF        F    |       |  5    |  00             | 
-^ INT IRQ        F    |       |  5    |  01             | +^ INT IRQ        F    |       |  5    |  01             | 
-^ INT FIQ        F    |       |  5    |  02             | +^ INT FIQ        F    |       |  5    |  02             | 
-^ INT IRQ,FIQ    F    |       |  5    |  03             | +^ INT IRQ,FIQ    F    |       |  5    |  03             | 
-^ FIR_MOV ON    |  F    |       |  5    |  04             | +^ FIR_MOV ON    |  F    |       |  5    |  04             | 
-^ FIR_MOV OFF    F    |       |  5    |  05             |+^ FIR_MOV OFF    F    |       |  5    |  05             |
 |                                                   | |                                                   |
-^ IRQ OFF        F    |       |  5    |  08             | +^ IRQ OFF        F    |       |  5    |  08             | 
-^ IRQ ON        |  F    |       |  5    |  09             |+^ IRQ ON        |  F    |       |  5    |  09             |
 |                                                   | |                                                   |
-^ FIQ OFF        F    |       |  5    |  0C             |+^ FIQ OFF        F    |       |  5    |  0C             |
 |                                                   | |                                                   |
-^ FIQ ON        |  F    |       |  5    |  0E             |+^ FIQ ON        |  F    |       |  5    |  0E             |
 |                                                   | |                                                   |
-NOP           |  F    |       |  5    |  25             |+BREAK         |  F    |       |  5    |  20             |
  
 FIXME probably other instructions (FRACTION, ...) fit in here FIXME probably other instructions (FRACTION, ...) fit in here
Line 60: Line 55:
 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    ^Opcode0^Operand A^Opcode1  ^6-bit Immediate +^Instruction    ^Opcode0^Operand A^Opcode1  ^6-bit Immediate  ^Condition   
-JCC, JB, JNAE |  0    |       |Direction| Jump offset     | +^ JB, JNAE, JCC |  0    |       |Direction| Jump offset     | C = 0      
-JCS, JNB, JAE |  1    |       |Direction| Jump offset     | +JAE, JNB, JCS |  1    |       |Direction| Jump offset     | C = 1      
-JSC, JGE, JNL |  2    |       |Direction| Jump offset     | +^ JGE, JNL, JSC |  2    |       |Direction| Jump offset     | S = 0      
-JSS, JNGE, JL |  3    |       |Direction| Jump offset     | +JL, JNGE, JSS |  3    |       |Direction| Jump offset     | S = 1      
-^ JNE, JNZ      |  4    |       |Direction| Jump offset     | +^ JNE, JNZ      |  4    |       |Direction| Jump offset     | Z = 0      
-^ JE, JZ        |  5    |       |Direction| Jump offset     | +^ JE, JZ        |  5    |       |Direction| Jump offset     | Z = 1      
-^ JPL            6    |       |Direction| Jump offset     | +^ JPL            6    |       |Direction| Jump offset     | N = 0      
-^ JMI            7    |       |Direction| Jump offset     | +^ JMI            7    |       |Direction| Jump offset     | N = 1      
-^ JBE, JNA      |  8    |       |Direction| Jump offset     | +^ JBE, JNA      |  8    |       |Direction| Jump offset     | !(Z=0&C=1) 
-JNBE, JA      |  9    |       |Direction| Jump offset     | +^ JA, JNBE       9    |       |Direction| Jump offset     | Z=0 & C=1  
-^ JLE, JNG      |  A    |       |Direction| Jump offset     | +^ JLE, JNG      |  A    |       |Direction| Jump offset     | !(Z=0&S=0) 
-JNLE, JG      |  B    |       |Direction| Jump offset     | +^ JG, JNLE       B    |       |Direction| Jump offset     | Z=0 & S=0  
-^ JVC            C    |       |Direction| Jump offset     | +^ JVC            C    |       |Direction| Jump offset     | N = S      
-^ JVS            D    |       |Direction| Jump offset     | +^ JVS            D    |       |Direction| Jump offset     | N != S     | 
-^ JMP            E    |       |Direction| Jump offset     |+^ JMP            E    |       |Direction| Jump offset     | Always     |
 |                F    |       | Reserved for special instructions || |                F    |       | Reserved for special instructions ||
  
-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 //following// the jump instruction, so an offset of 0 would jump to the next instruction (basically a NOP) while a offset of -1 (1 backwards) would be an infinite loop and a offset of (+1would skip a single instruction.
  
 ===== ALU instructions ===== ===== ALU instructions =====
  
-^Instruction    ^Opcode0^Operand A^Opcode1  ^OPN         ^Operand B^ +^Instruction    ^Opcode0^Operand A    ^Opcode1  ^OPN           ^Operand B^ 
-^ ADD            0    |  Op. A  |Addr Mode|Param       | Op. B   | +^ ADD            0    |Op. A        |Addr Mode|Param         | Op. B   | 
-^ ADC            1    |  Op. A  |Addr Mode|Param       | Op. B   | +^ ADC            1    |Op. A        |Addr Mode|Param         | Op. B   | 
-^ SUB            2    |  Op. A  |Addr Mode|Param       | Op. B   | +^ SUB            2    |Op. A        |Addr Mode|Param         | Op. B   | 
-^ SBC            3    |  Op. A  |Addr Mode|Param       | Op. B   | +^ SBC            3    |Op. A        |Addr Mode|Param         | Op. B   | 
-^ CMP            4    |  Op. A  |Addr Mode|Param       | Op. B   | +^ CMP            4    |Op. A        |Addr Mode|Param         | Op. B   | 
-|                             |                    |         | +|                                 |                      |         | 
-^ NEG            6    |  Op. A  |Addr Mode|Param       | Op. B   | +^ NEG            6    |Op. A        |Addr Mode|Param         | Op. B   | 
-|                             |                    |         | +|                                 |                      |         | 
-^ XOR            8    |  Op. A  |Addr Mode|Param       | Op. B   | +^ XOR            8    |Op. A        |Addr Mode|Param         | Op. B   | 
-^ LD            |  9    |  Op. A  |Addr Mode|Param       | Op. B   | +^ LD            |  9    |Op. A        |Addr Mode|Param         | Op. B   | 
-^ POP            9    |First reg - 1|      |Register count| Stack pointer reg | +^ POP            9    |First reg - 1|2        |Register count| Stack pointer reg | 
-^ RETF          |  9    |  5 (SR) |       | 2 (SR, PC) | 0 (SP)  | +^ RETF          |  9    |5 (SR)       |2        |2 (SR, PC)    | 0 (SP)  | 
-^ RETI          |  9    |  5 (SR) |       | 3 (SR, PC, FR) | 0 (SP)  | +^ RETI          |  9    |5 (SR)       |2        |3 (SR, PC, FR)| 0 (SP)  | 
-^ OR            |  A    |  Op. A  |Addr Mode|Param       | Op. B   | +^ OR            |  A    |Op. A        |Addr Mode|Param         | Op. B   | 
-^ AND            B    |  Op. A  |Addr Mode|Param       | Op. B   | +^ AND            B    |Op. A        |Addr Mode|Param         | Op. B   | 
-^ TEST          |  C    |  Op. A  |Addr Mode|Param       | Op. B   | +^ TEST          |  C    |Op. A        |Addr Mode|Param         | Op. B   | 
-^ ST            |  D    |  Op. A  |Addr Mode|Param       | Op. B   | +^ ST            |  D    |Op. A        |Addr Mode|Param         | Op. B   | 
-^ PUSH          |  D    |Last reg -1|  2    |Register count| Stack pointer reg  | +^ PUSH          |  D    |Last reg -1  |  2      |Register count| Stack pointer reg  | 
-|                             |                    |         | +|                                 |                      |         | 
-|                F    |  Reserved for special instructions  ||||+|                F    |  Reserved for special instructions   ||||
  
 Depending on opcode1, various addressing modes can be used: Depending on opcode1, various addressing modes can be used:
  
-^Addressing mode^Opcode0^Operand A^Opcode1  ^OPN         ^Operand B^ +^Addressing mode    ^Opcode0^Operand A^Opcode1  ^OPN               ^Operand B^ ^Notes       
-^ [BP+Imm6]     | ALU op|  Op. A  | 0        6-bit immediate    || +^%% [BP+Imm6]     %%| ALU op|  Op. A  | 0        6-bit immediate          || | Op. A ≠ PC 
-^ #Imm6         | ALU op|  Op. A  | 1        6-bit immediate    || +^%% #Imm6         %%| ALU op|  Op. A  | 1        6-bit immediate          || | Op. A ≠ PC 
-| Special (POP, PUSH) |         | 2                  |         | +| Special (POP, PUSH) |             | 2                        |         | 
-^ [Rs]          | ALU op|  Op. A  | 3       | 0          | Rs      | +^%% [Rs]          %%| ALU op|  Op. A  | 3       | 0                | Rs      | 
-^ [Rs--]        | ALU op|  Op. A  | 3       | 1          | Rs      | +^%% [Rs--]        %%| ALU op|  Op. A  | 3       | 1                | Rs      | 
-^ [Rs++]        | ALU op|  Op. A  | 3       | 2          | Rs      | +^%% [Rs++]        %%| ALU op|  Op. A  | 3       | 2                | Rs      | 
-^ [++Rs]        | ALU op|  Op. A  | 3       | 3          | Rs      | +^%% [++Rs]        %%| ALU op|  Op. A  | 3       | 3                | Rs      | 
-^ D:[Rs]        | ALU op|  Op. A  | 3       | 4          | 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  | 3       | 5                | Rs      | 
-^ D:[Rs++]      | ALU op|  Op. A  | 3       | 6          | Rs      | +^%% D:[Rs++]      %%| ALU op|  Op. A  | 3       | 6                | Rs      | 
-^ D:[++Rs]      | ALU op|  Op. A  | 3       | 7          | Rs      | +^%% D:[++Rs]      %%| ALU op|  Op. A  | 3       | 7                | Rs      | 
-^ Rs            | ALU op|  Op. A  | 4       | 0          | Rs      | +^%% Rs            %%| ALU op|  Op. A  | 4       | 0                | Rs      | 
-^ #Imm16        | ALU op|  Op. A  | 4       | 1          Rs      | |16-bit immediate in next word| +^%% #Imm16        %%| ALU op|  Op. A  | 4       | 1                Unused  | |16-bit immediate in next word| 
-^ From [Addr16] | ALU op|  Op. A  | 4       | 2          Rs      | |16-bit address in next word| +^%% From [Addr16] %%| ALU op|  Op. A  | 4       | 2                Unused  | |16-bit address in next word| 
-^ To [Addr16]   | ALU op|  Op. A  | 4       | 3          Rs      | |16-bit address in next word **(ISA 1.2 only)** +^%% To [Addr16]   %%| ALU op|  Op. A  | 4       | 3                Unused  | |16-bit address in next word| 
-^ Rs ASR shift  | ALU op|  Op. A  | 4       shift  | Rs      | +^%% Rs ASR shift  %%| ALU op|  Op. A  | 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      | 
-^ Rs LSR shift  | ALU op|  Op. A  | 5       shift  | Rs      | +^%% Rs LSR shift  %%| ALU op|  Op. A  | 5       (shift - 1)  | Rs      | 
-^ Rs ROL shift  | ALU op|  Op. A  | 6       | shift - 1  | Rs      | +^%% Rs ROL shift  %%| ALU op|  Op. A  | 6       | shift - 1        | Rs      | 
-^ Rs ROR shift  | ALU op|  Op. A  | 6       shift  | Rs      | +^%% Rs ROR shift  %%| ALU op|  Op. A  | 6       (shift - 1)  | Rs      | 
-^ [Addr6]       | ALU op|  Op. A  | 7        6-bit address      ||+^%% [Addr6]       %%| ALU op|  Op. A  | 7        6-bit address            ||
  
 The instructions using Imm16 or Addr16 are 3-operand instructions, for example: The instructions using Imm16 or Addr16 are 3-operand instructions, for example:
Line 133: Line 128:
 ''R3 = R2 + Imm16'' ''R3 = R2 + Imm16''
  
-smasm syntax:+naken_asm syntax:
  
 ''ADD R3, R2, #Imm16'' ''ADD R3, R2, #Imm16''
Line 142: Line 137:
  
 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]" would be something like this:
 +
 +''R3 = R2 + [Addr16]''
 +
 +and the "To [Addr16]" corresponds to:
 +
 +''[Addr16] = R2 + R3''
 +
 +(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.
instruction_encoding.1615464897.txt.gz · Last modified: 2021/03/11 13:14 by pulkomandy
CC Attribution 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0