Lecture 5
:material-circle-edit-outline: 约 449 个字 :fontawesome-solid-code: 2 行代码 :material-clock-time-two-outline: 预计阅读时间 2 分钟
240326
!!! bug “我真的服了” 这个老师会传统点名
接上周没讲完的 jump 跳转
Jump
Basic Blocks
跳转让优化变得很困难,因为跳转是未知的、不确定的。
为了方面预测并优化,将指令集合分为多个basic block,每个block里面不会进行jump,还有一些其它的性质:
- A basic block is a sequence of instructions with
- No embedded branches (except at end)
- No branch targets (except at beginning)
2.8 Supporting Procedures
Procedure/function
- Procedure/function be used to structure programs
- A stored subroutine that performs a specific task based on the parameters with which it is provided
- Six step
- Place Parameters in a place where the procedure can access them
- Transfer control to the procedure(jump to)
- Acquire the storage resources needed for the procedure
- Perform the desired task
- Place the result value in a place where the calling program can access it
- Return control to the point of origin
Procedure Call Instructions
- Instruction for procedures:
jal ( jump-and-link )
- Address of following instruction put in x1
- Jumps to target address
- Procedure return:
jalr (jump and link register)
- Like jal, but jumps to 0 + address in x1
- Use x0 as rd (x0 cannot be changed)
- Can also be used for computed jumps
Using More Registers
- Registers for procedure calling
a0 ~ a7(x10-x17)
: eight argument registers to pass parameters & return valuesra/x1
:one return address register to return to origin point
- Stack
- ideal data structure for spilling registers
- Stack pointer sp
- Stack grow from higher address to lower address
- 约定起始位置在高位,往低位扩张
- Push: sp= sp - 8
addi sp,sp,-8 sd …,8(sp)
- Pop: sp = sp + 8
ld …,8(sp) addi sp,sp,
- 8 是字长
Example
这里没听没看
下面虚线部分是运算部分,可以忽略
记成tx是方便,就一个临时记号
Nested Procedures
下面都没看
嵌套程序
一个stack不够用,用多个stack
Memory Layout
Local Data on the Stack
RISC-V assembly language
这张表经常要查
2.9 Communicating with People Character Data
- Byte-encoded character sets
- ASCII ( American Standard Code for Information Interchange )
- Unicode: 32-bit character set
Byte/Halfword/Word Operations
String Copy Example
2.10 Addressing for 32-Bit Immediate and Addresses
Addressing
Branch Addressing
Jump Addressing
Show branch offset in machine language
Instructions Addressing and their Offset