寻址方式:指令的地址码域 ·寻址方式:指令字和操作数的存储地址计算方式 ·指令寻址:现代CPU利用PC -顺序执行:每执行一条指令,PC自动1 一跳转:更新PC,转移到目的地址执行 操作数寻址 一指令中给出“形式地址” 一有效地址:操作数在寄存器/内存中的物理地址 ·EA=寻址方式+形式地址 Control Arithmetic Internal Unit Logic Unit data bus Registers 操作码 Instruction 形式地址 Decoder llxx@ustc.edu.cn 16/41
llxx@ustc.edu.cn 16/41 寻址方式:指令的地址码域 • 寻址方式:指令字和操作数的存储地址计算方式 • 指令寻址:现代CPU利用PC – 顺序执行:每执行一条指令,PC自动1 – 跳转:更新PC,转移到目的地址执行 • 操作数寻址 – 指令中给出“形式地址” – 有效地址:操作数在寄存器/内存中的物理地址 • EA=寻址方式+形式地址 操作码 形式地址
寻址方式:操作数,下一条指令 常见约10种 Instruction Instruction Instruction Operand A A 立即寻址(a) Memory Memory 直接寻址(b) Operand 一间接寻址(c) Operand - 寄存器寻址(d) (a)Immediate (b)Direct (c)Indirect 一寄存器间接寻址 (e) Instruction Instruction Instruction R R 基址寻址(f) Memory Memory ·BP+offset ◆Operand -PC相对寻址(f) Operand Operand Registers Registers Registers ·PC+offset (d)Register (e)Register indirect (f)Displacement -堆栈寻址(g) Instruction - 变址寻址(d+f) Implicit 有效地址计算步骤? ·Index:x86的si/di 最少必须哪几种? Top of stack 一隐含寻址(如堆栈) register 指令寻址有哪些方式? (g)Stack 17/41
17/41 寻址方式:操作数,下一条指令 • 常见约10种 – 立即寻址(a) – 直接寻址(b) – 间接寻址(c) – 寄存器寻址(d) – 寄存器间接寻址(e) – 基址寻址(f) • BP+offset – PC相对寻址(f) • PC+offset – 堆栈寻址(g) – 变址寻址(d+f) • Index:x86的si/di – 隐含寻址(如堆栈) 有效地址计算步骤? 最少必须哪几种? 指令寻址有哪些方式?
寻址方式示例 addi Ripes File Help 。j 〈>>010s日》☒田 68 SW 01 Source code Executable code view mode:O Binary ODisassenbled Editor main: beq 2 addi x2,x0,2 00000000<main>: 3 addi x3,x0,3 0: 00200113 addi x2 x0 2 IF 4 addi x7,x3,-6 4: 00300193 addi x3 x0 3 5 8: ffa18393 addi x7 x3-6 6 j end c: 0080806f jal x0 0x14 <enc 7 addi x2,x0,2 10: 00200113 addi x2 x0 2 8 9 end: 00009014<end>: 10swX2,45(x0) 14: 022026a3 swX245(x0) 11 beq x7,x5,main 18: fe5384e3 beq x7 x5 -24 <r
寻址方式示例 • addi • j • sw • beq
RISC-VISA的特点 模块化:51+13+133 -RV32I指令集:支持完整软件栈,永远不变 ·共51条:图2-1(37条,重点)+图2-37(14条) 一 系统指令:同步,CSR操作,异常。图5-47,13条 -RV32IMFD指令集:RV32I的基本扩展,133条 图2-38 约束 Mnemonic Description Insn.Count 成本:芯片面积 Base architecture 51 M Integer multiply/divide 13 简洁 A Atomic operations 22 - 性能:时间,功耗 Single-precision floating point 30 D Double-precision floating point 32 一架构与实现分离 Compressed instructions 36 - 扩展性:操作码域空间 程序大小 一易于编程/编译/链接 RISC-I RISC-II RISC-III(SOAR)RTSC-TV (SPUR) RISC-V 1981 1983 1984 1988 2013
RISC-V ISA的特点 • 模块化:51+13+133 – RV32I指令集:支持完整软件栈,永远不变 • 共51条:图2-1(37条,重点)+ 图2-37(14条) – 系统指令:同步,CSR操作,异常。图5-47,13条 – RV32IMFD指令集: RV32I的基本扩展,133条 • 约束 – 成本:芯片面积 – 简洁 – 性能:时间,功耗 – 架构与实现分离 – 扩展性:操作码域空间 – 程序大小 – 易于编程/编译/链接 图2-38
RISC-V指令格式与寻址方式 图2-19 Name Field Comments (Field size) 7 bits 5 bits 5 bits 3 bits 5 bits 7 bits R-type funct7 rs2 rs1 funct3 rd opcode Arithmetic instruction format I-type immediate[11:0] rs1 funct3 rd opcode Loads immediate arithmetic S-type immed[11:5] rs2 rs1 funct3 immed[4:0] opcode Stores SB-type immed12,10:5] rs2 rs1 funct3 immed[4:1,11] opcode Conditional branch format UJ-type immediate[20,10:1,11,19:12] rd opcode Unconditional jump format U-type immediate[31:12] rd opcode Upper immediate format 1.Immediate addressing funct6 immed rs1 funct3 rd opcode 指令格式:6种 immediate rs1 funct3 rd op - 基本:RI/S/U 1S型$2.6 ·7种:4+2+“1S” 2.Register addressing 图2-17 ·lS-type:functe6,立即数移位 funct7 rs2 rs1 funct3 rd op Registers 规整:Reg和lmm位置固定 Register ·BJ-type的立即数域? op码与类型绑定 3.Base addressing - immediate rs1 funct3rd op Memory 寻址方式:4种 Register Byte]Halfword Word Doubleword - 本质:lmm,Reg,Base 指令寻址方式 4.PC-relative addressing imm rs2 rs1 funct3imm op ·PC相对寻址:beq,jal Memory ·间接跳转:jalr x0,100(x1) PC Word
RISC-V指令格式与寻址方式 • 指令格式:6种 – 基本:R/I/S/U • 7种:4+2+“IS” • IS-type:funct6,立即数移位 – 规整:Reg和Imm位置固定 • B/J-type的立即数域? – op码与类型绑定 • 寻址方式:4种 – 本质:Imm,Reg,Base – 指令寻址方式 • PC相对寻址:beq,jal • 间接跳转:jalr x0,100(x1) 图2-17 图2-19 IS型$2.6