A Detailed Instruction to a Subset of RISC-V Instructions

1. Computational Instrucitions

1.1 R-type:register-register instructions

  • opcode = OP = 0110011
ArithmeticComparisonsLogicalShifts
ADD,SUBSLT,SLTUAND,OR,XORSLL,SRL,SRA
  • Assembly instr: oper rd,rs1,rs2
  • Behavior: reg[rd] <= reg[rs1] oper reg[rs2]
OperatorComplete representation
SLTSet less than
SLTUSet less than unsigned
SLLShift left logical
SRLShift right logical
SRAShift right arithmetic

1.2 I-type:Register immediate instructions

opcode = OP-IMM = 0010011

ArithmeticComparisonsLogicalShifts
ADDISLTI,SLTIUANDI,ORI,XORISLLI,SRLI,SRAI
  • Assembly instr: opr rd,rs,immI
  • Behavior: imm = signExtend(immI) reg[rd] <= reg[rs1] opr imm

在这里插入图片描述

1.3 U-type

  • opcode = LUI OR AUIPC =(01|00)10111
  • Assembly instr: lui rd,immU
  • Behavior: imm = {immU,12’b0} Reg[rg] <= imm
  • immU is a 20 bit constant
OperatorComplete Representation
LUILoad Upper Immediate
AUIPCAdd Upper Immediate to PC

2. Load Store Instructions

2.1 I-type

  • Load:with operator = LOAD = 0000011
  • Assembly instr: lw rd,immI(rs1)
  • Behavior:imm = signExtend(immI) Reg(rd) <= Mem[Reg(rs1) + imm]
OperatorComplete Representation
LWLoad Word

2.2 S-type

  • Store:with operator = STORE = 0100011
  • Assembly instr: sw rs2,immS(rs1)
  • Behavior:imm = signExtend(immS) Mem[Reg[rs1] + imm] <= Reg[rs2]
OperatorComplete Representation
SWSave Word

3. Control Instructions

3.1 SB-type

  • Conditional Branches: opcode = 110011
  • Assembly instr: oper r1,r2,label
  • Behavior:imm = distance to label in bytes = {immS[12:1],0} pc <= (R[rs1] comp R[rs2] ? pc + imm:pc + 4)
  • Compares register rs1 to rs2. If comparison is true then pc is updated with pc + imm, otherwise pc becomes pc + 4. Comparison type is defined by operation.
OperatorComplete Representation
BEQbranch if equal
BNEbranch if not equal (!=)
BLTbranch if less than (<)
BGEbranch if greater than or equal (>=)
BLTUbranch if less than using unsigned numbers (< unsigned)
BGEUbranch if greater than or equal using unsigned numbers (>= unsigned)

3.2 UJ-type

3.2.1 JAL
  • Unconditional Jump
  • opcode = JAL = 1101111
  • Assembly instr: JAL rd,label
  • Behavior:imm = distance to label in bytes = {immU{20:1},0} pc[rd] <= pc + 4; pc <= pc + imm
  • Promblem:what is the structure of pc?what is pc[rd]?
3.2.2 I-type JAL
  • Unconditional Jump
  • opcode = JALR = 1100111
  • Behavior: imm = SignExtend(immI) pc[rd] <= pc + 4; pc <= (R[rs1]+imm) & ~0x01
  • (zero out the bottom bit of pc)
    在这里插入图片描述
    -Problem:I can’t understand the behavior of JALR
OperatorComplete Representation
JALjump and link
JALRjump and link register

4. Common Pseudoinstructions

PseudoinstructionEquivalent Assembly Instruction
j labeljal x0, label (ignore return address)
li x1, 0x1000lui x1, 1
li x1, 0x1100lui x1, 1; addi x1, x1, 0x100
li x4, 3addi x4, x0, 3
mv x3, x2addi x3, x2, 0
beqz x1, targetbeq x1, x0, target
bneqz x1, targetbneq x1, x0, target

5. Reference Card

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值