cpu32/INSTRUCTIONS.md

213 lines
4.5 KiB
Markdown
Raw Permalink Normal View History

2022-10-29 23:29:17 +02:00
# RISC combined instruction set
goal: a semi-efficient insatruction set that offers few instructions that offer
the combined functions of conventional risc instuctions.
as such most instructions could be pipelined, I don't know how to feel about that
2022-10-30 00:05:19 +02:00
# Memory Operations
when accessing memory trough an address a consecutive pair of registers is used,
each consecutive pair of registers is given a name, for brevity a pair is
always referred to as `A`. The possible pairs are:
- A = R1:R0
- B = R3:R2
- C = R5:R4
- D = R7:R6
- E = R9:R8
- F = R11:R10
- G = R13:R12
- H = R15:R14
- I = R17:R16
- J = R19:R18
- K = R21:R20
- L = R23:R22
- M = R25:R24
- N = R27:R26
- O = R29:R28
- P = R31:R30
2022-10-31 00:23:48 +01:00
### LD load value into register
2022-10-30 00:05:19 +02:00
post increment/decrement
syntax: `LD Rd, A+q`
action: `Rd = [A]; A += q`
pre increment/decrement
syntax: `LD Rd, q+A`
action: `A += q; Rd = [A]`
2022-10-31 00:23:48 +01:00
### LDI load immediate into register
2022-10-30 00:05:19 +02:00
syntax: `LDI Rd, imm`
action: `Rd = imm`
2022-10-31 00:23:48 +01:00
### LDIL load long immediate into register
2022-10-30 00:05:19 +02:00
syntax: `LDIL Rd, imm32`
action: `Rd = imm32`
2022-10-31 00:23:48 +01:00
### ST store value from register
2022-10-30 00:05:19 +02:00
post increment/decrement
syntax: `ST A+q, Rd`
action: `[A] = Rd; A += q`
pre increment/decrement
syntax: `ST q+A, Rd`
action: `A += q; [A] = Rd`
2022-10-31 00:23:48 +01:00
### STI store immediate into memory
2022-10-30 00:05:19 +02:00
post increment/decrement
syntax: `STI A+q, imm`
action: `[A] = imm; A += q`
pre increment/decrement
syntax: `STI q+A, imm`
action: `A += q; [A] = imm`
2022-10-31 00:23:48 +01:00
### STIL store long immediate into memory
2022-10-30 00:05:19 +02:00
post increment/decrement
syntax: `STIL A+q, imm32`
action: `[A] = imm32; A += q`
pre increment/decrement
syntax: `STIL q+A, imm32`
action: `A += q; [A] = imm32`
2022-10-30 12:55:44 +01:00
# Arithmetic operations
2022-10-31 00:23:48 +01:00
### ADD
### ADDC
### ADDI
### ADDIC
2022-10-30 12:55:44 +01:00
2022-11-06 15:42:35 +01:00
### SUB Subtract
### SUBC Subtract with carry
### SUBI Subtract immediate
### SBIC Subtract immediate with carry
2022-10-31 00:23:48 +01:00
### MLA Multiply and add
2022-10-30 12:55:44 +01:00
syntax: `MLA A, Ra, Rb, Rc`
action: `A = Rc + (Ra * Rb)`
2022-10-31 00:23:48 +01:00
### MLAI Multiply and add immediate
2022-10-30 12:55:44 +01:00
syntax: `MLAI A, Ra, Rb, imm`
action: `A = imm + (Ra * Rb)`
2022-10-31 00:23:48 +01:00
### MLIA Multiply immediate and add
2022-10-30 12:55:44 +01:00
syntax: `MLIA A, Ra, imm, Rc`
action: `A = Rc + (Ra * imm)`
2022-10-31 00:23:48 +01:00
### MLAC Multiply and add with carry
2022-10-30 12:55:44 +01:00
syntax: `MLAC A, Ra, Rb, Rc`
action: `A = F.C + Rc + (Ra * Rb)`
2022-10-31 00:23:48 +01:00
### MLAIC Multiply and add immediate with carry
2022-10-30 12:55:44 +01:00
syntax: `MLAIC A, Ra, Rb, imm`
action: `A = F.C + imm + (Ra * Rb)`
2022-10-31 00:23:48 +01:00
### MLIAC Multiply immediate and add with carry
2022-10-30 12:55:44 +01:00
syntax: `MLIAC A, Ra, imm, Rc`
action: `A = F.C + Rc + (Ra * imm)`
2022-10-31 00:23:48 +01:00
### SMLA Signed multiply and add
2022-10-30 12:55:44 +01:00
syntax: `SMLA A, Ra, Rb, Rc`
action: `A = Rc + (Ra * Rb)`
2022-10-31 00:23:48 +01:00
### SMLAI Signed multiply and add immediate
2022-10-30 12:55:44 +01:00
syntax: `SMLAI A, Ra, Rb, imm`
action: `A = imm + (Ra * Rb)`
2022-10-31 00:23:48 +01:00
### SMLIA Signed multiply immediate and add
2022-10-30 12:55:44 +01:00
syntax: `SMLIA A, Ra, imm, Rc`
action: `A = Rc + (Ra * imm)`
2022-10-31 00:23:48 +01:00
### SMLAC Signed multiply and add with carry
2022-10-30 12:55:44 +01:00
syntax: `SMLAC A, Ra, Rb, Rc`
action: `A = F.C + Rc + (Ra * Rb)`
2022-10-31 00:23:48 +01:00
### SMLAIC Signed multiply and add immediate with carry
2022-10-30 12:55:44 +01:00
syntax: `SMLAIC A, Ra, Rb, imm`
action: `A = F.C + imm + (Ra * Rb)`
2022-10-31 00:23:48 +01:00
### SMLIAC Signed multiply immediate and add with carry
2022-10-30 12:55:44 +01:00
syntax: `SMLIAC A, Ra, imm, Rc`
action: `A = F.C + Rc + (Ra * imm)`
2022-11-06 15:42:35 +01:00
### MUL, MULS, IMUL, MULI, etc.
can be macro'd with multiply and adds
2022-10-30 12:55:44 +01:00
2022-10-31 00:23:48 +01:00
### AND
### ANDI with immediate
### OR
### ORI with immediate
### XOR
### XORI with immediate
2022-10-30 12:55:44 +01:00
2022-10-31 00:23:48 +01:00
### NEG negate (two's complement)
2022-10-30 12:55:44 +01:00
2022-10-31 00:23:48 +01:00
### ROR Rotate right
### ROL Rotate left
### SHR Shift right
### SHRC Shift right through carry
### SHL Shift left
### SHLC Shift left through carry
2022-10-30 12:55:44 +01:00
# Conditional operations
2022-10-31 00:23:48 +01:00
### JZS Jump on zero set
syntax: `JZS imm32`
### JZC Jump on zero clear
### RJZS Relative jump on zero set
syntax: `RJZS imm`
### RJZC Relative jump on zero clear
### JNS Jump on negative set
### JNC Jump on negative clear
### RJNS Relative jump on negative set
### RJNC Relative jump on negative clear
### JCS Jump on carry set
### JCC Jump on carry clear
### RJCS Relative jump on carry set
### RJCC Relative jump on carry clear
### JVS Jump on overflow set
### JVC Jump on overflow clear
### RJVS Relative jump on overflow set
### RJVC Relative jump on overflow clear
# Stack manipulation
### CALL
2022-11-06 15:42:35 +01:00
could be implemented with push/jump
2022-10-31 00:23:48 +01:00
### RCALL
2022-11-06 15:42:35 +01:00
could be implemented with pop/jump
2022-10-31 00:23:48 +01:00
### PUSH
### POP
2022-11-06 15:42:35 +01:00
2022-11-07 18:20:54 +01:00
# Planned features
2022-11-06 15:42:35 +01:00
- 1-cycle shift and add
- 1-cycle intger division
- interrupts
2022-11-07 18:20:54 +01:00
- timers
* watchdog timers
2022-11-06 15:42:35 +01:00
- atomic compare-and-swap
- atomic load-link/store-conditional
- memory management
- memory-mapped registers
2022-11-07 18:20:54 +01:00
- co-processor design and abi
* sine and cosine functions as co-processor, see [cordic][1]
* floating point arithmetic
* cryptographic functions as a co-processor
- AES
- CRC32
- Parity check
- md5
- SHA-1
- SHA-256
2022-11-06 15:42:35 +01:00
[1]: https://en.wikipedia.org/wiki/CORDIC