- 16-bit fixed length instructions, with 2 types of instructions
- Type-A : 2 operands, 5-bit respectively
- Type-B : 1 operand of 5-bit
- Solution I : Make same format -> MSB로 Type A, B 구별 -> 2^5 + 2^5 = 64
- Solution II : Expand opcode -> Type-A를 고정함으로써 구별
-> if Type-A 가 1일 경우 -> 1 + (2^6 - 1) x 2^5
-> if Type-A 가 10일 경우 -> 10 + (2^6 - 10) x 2^5
-> Type-A 가 작을 수록 만들 수 있는 명령어의 갯수는 최대
Need three operands : one for destination and two sources
- ex) add a, b, c / a <- b + c
- ex) sub, a, b, c / a <- b - c
Data in memory cannot be addressed directly ALU instructions
- Compiler must use data in register
- Register is faster -> Register optimization
R-Type instruction format
- opcode : basic operation
- rd : destination register
- rs1, rs2 : source register
- func3, func7 : additional opcode
R-Type opcode
opcode 로 구분하지 않고 func 으로 구분하는 이유?
-> opcode 의 bit 조작 없이 func 만 추가하면 되므로 설계가 더 간단하고 확장에 유리하다.
- SLL (SRL) : Shift Left (Right) Logical
- SLL: The low-order bit is replaced by a zero bit and
the high-order bit is discarded.- SRL: The high-order bit is replaced by a zero bit and
the low-order bit is discarded.- SRA : Shift Right Arithmetic
- Vacant bits are filled with sign bit (Sign extension)
- SLA does not need to be supported because MSB will be discarded
- SLT : Set Less Than
- SLT, rd, rs1, rs2 => if rs1 < rs2 then: 1 else: 0
- SLT(U) : Set Less Than (Unsigned)
- 부호 고려하지 않고 Comparison
- ex) addi x22, x22, 4 => x22 <- x22 + 4
- The range of imm is from -2^11 to 2^11 - 1
- Imm is sign extended to 32-bits
- ex) ld, x2, 16(x3) => x2 <- x3 + offset(16)
- lb(sign extend) vs lbu(zero extend)!
- no need the destination address of register
Branch : change of control flow
- Conditional branch : change control flow depending on outcome of comparison
- Unconditional branch : just branch
Branch instruction format
- beq : branch if equal
- bne : branch if not equal
- blt : branch if less than
- bge : branch if greater than
- bltu, bgeu : unsigned
imm field is 13 bits because imm[0] is assumed to be always 0
if moving individual lines of code, branch immediate field should be changed
if moving all of code, branch immediate field does not need to be changed -> branch immediate field has PC-relative offsets
There are times when constants are too big to fit into 12 bits
Load 20bit constant into position 31~12
Rightmost 12 bits should be zero
possible to create 32-bit value by addi
there is an issue when using addi due to sign-extended
- solution : Assembler can handle this problem by using pseudo-instructions
꾸벅