본문 바로가기
IT_Study/CS_Study

[Computer Architecture] (7) Instruction Example

by 두번째얼룩 2024. 4. 28.

RISC-V Instruction Formats은 아래와 같이 크게 6가지가 있다.

1. R-Type

2. I-Type

3. S-Type

4. SB-Type

5. U-Type

6. UJ-Type

각 format을 알아보고, 어떻게 Instruction을 만들 수 있는 지 확인해보자.

 

1. R-Type

R-Type

add 명령어는 아래와 같이 구분될 수 있다.

// add
// func7  : 7'h00
// rs2    : 5'h7;
// rs1    : 5'h6;
// func3  : 3'h0
// rd     : 5'h5;
// opcode : 7'h33

add x5, x6, x7 # a5 = a6 + a7

이를 배치하면 아래와 같다.

add x5, x6, x7 -> instrucion

2. I-Type

I-Type

// addi
// imm    : 12'hFCE, 12'b1111 1100 1110 -> +50의 2's complement 표현.
// rs1    : 5'h1;
// func3  : 3'h0
// rd     : 5'hF;
// opcode : 7'h13
addi x15,x1,-50

Shift right arithmetic/logical 구분법

 

addi x15, x1, -50 -> Instruction

3. S-Type

S-Type

// sw
// imm    : 12'h8
// rs1    : 5'h2
// func3  : 3'h2
// rd     : 5'hE
// opcode : 7'h23
sw x14, 8(x2)

 

4. SB-Type

SB-Type

// bne
// imm    : 12'd2000, 12'h7D0, 12'b111_1101_0000
// rs2    : 5'hB
// func3  : 3'h1
// rs1    : 5'hA
// opcode : 7'h63
bne x10,x11,2000

 

bne x10, x11, 2000 -> instruction

5. U-Type

U-Type

// lui
// imm    : 20'd2000, 12'h7D0, 12'b111_1101_0000
// rd      : 5'hA
// opcode : 7'h63
lui x10, 2000

lui x10, 2000

6. UJ-Type

UJ-Type

// jal
// imm    : 20'd2000, 20'h7D0, 20'b0000_0111_1101_0000
// rd     : 5'h0
// opcode : 7'h6f
jal x0, 2000

jal x0, 2000 -> instruction

댓글