KOSMOS-16 ISA Specification

opcode - код операции
rd - регистр-назначение
rs - регистр-источник
functN - дополнительный код операции, N указывает величину в битах

opcode значение
000 R-type (регистр + регистр)
001 I-type (регистр + immediate)
010 S-type (запись значения регистра в память)
011 L-type (загрузка значения из памяти в регистр) + JALR
100 B-type (прыжок с условием)
101 UJ-type (безусловный прыжок)
110 LI-type (загрузка константы)
111 Syscalls

Регистры

8 16-битных регистров

Регистр Назначение Двоичный адрес
x0 Всегда равен нулю, запись невозможна 000
x1 Return Address, адрес возврата 001
x2 Stack pointer, указатель на область стэка памяти 010
x3
x4-x7 General Purpose регистры

R-type

Операции с двумя регистрами с сохранением результата в третий.

3 bit 3bit 3bit 4bit 3bit
rd rs1 rs2 funct4 opcode

r-type

Инструкции

Инструкция funct4 Операция
ADD 0000 \(rd \leftarrow rs1+rs2\)
SUB 0001 \(rd \leftarrow rs1-rs2\)
SLL 0010 \(rd \leftarrow rs1 \ll rs2\)
SRL 0011 \(rd \leftarrow rs1 \gg rs2\), logical
OR 0100 \(rd \leftarrow rs1 \lor rs2\)
XOR 0101 \(rd \leftarrow rs1 \oplus rs2\)
AND 0110 \(rd \leftarrow rs1 \land rs2\)
SLT 0111 \(rd \leftarrow (rs1 < rs2)\), signed
SLTU 1000 \(rd \leftarrow (rs1 < rs2)\), unsigned
SRA 1001 \(rd \leftarrow rs1 \gg rs2\), arithmetic
NOR 1010 \(rd \leftarrow \neg(rs1 \lor rs2)\)
Reserved 1011–1111 Available for future instructions

I-type

Операции с одним регистром и непосредственным значением (immediate). Результат сохраняется в тот же регистр.

3 bit 7bit 3bit 3 bit
rd\rs1 imm funct3 opcode

i-type

Инструкции

Инструкция funct3 Операция
ADDI 000 Add signed immediate
SLLI 001 Logical left shift
SRLI 010 Logical right shift
SRAI 011 Arithmetic right shift
ORI 100 Bitwise OR with immediate
XORI 101 Bitwise XOR with immediate
ANDI 110 Bitwise AND with immediate
Reserved 111 Available for future instructions

S-type

Stores.

3 bit 3 bit 3 bit 3 bit 1bit 3 bit
imm[5:3] rs1 rs2 imm[2:0] funct1 opcode

Записывает значение rs2 по адресу rs1 + смещение imm

Инструкции

Instruction funct1 Operation
SB 0 Store the lowest 8 bits of rs2
SH 1 Store all 16 bits of rs2

L-type

Loads and JALR.

3 bit 3 bit 5bit 2bit 3 bit
rd rs1 imm funct2 opcode

Инструкции

Instruction funct2 Operation
LB 00 Load 8 bits to rd on memory address rs1 + signed(immediate) and sign-extends.
LH 01 Load 16 bits to rd on memory addressrs1 + signed(immediate)
LBU 10 Load 8 bits to rd on memory address rs1 + signed(immediate) and zero-extends
JALR 11 Jump And Link Register. Jumps by address in rs1 + signed(immediate) and store PC+2 in rd

B-type

Условный переход на основе сравнения двух регистров.

3 bit 3 bit 3 bit 2 bit 2 bit 3 bit
imm[4:2] rs1 rs2 imm[1:0] funct2 opcode

Переход выполняется, если условие сравнения регистров rs1 и rs2 выполняется. Смещение imm определяет адрес перехода относительно текущего PC.

Инструкции

Instruction funct2 Operation
BEQ 00 Branch if rs1 is equal tors2
BNE 01 Branch if rs1 is not equal to rs2
BGE 10 Branch if rs1 is greater than or equal rs2
BLTU 11 Branch if rs1 is less than rs2

J-type

Безусловный переход с сохранением адреса возврата в регистр rd.

3 bit 10 bit 3 bit
rd immediate opcode

Адрес следующей инструкции сохраняется в rd, после чего выполняется переход на смещение imm относительно текущего PC.
imm относительно текущего PC.

U-type

Upper immediate instructions. These instructions load an immediate value into the upper portion of a register or construct a PC-relative address.

rd imm funct1 opcode
3 bits 9 bits 1 bit 3 bits

Инструкции

Instruction Operation funct1
LUI Load upper immediate into rd 0
AUIPC Add upper immediate to the current PC and store the result in rd 1