当前位置:网站首页>RISC-V calling conventions
RISC-V calling conventions
2022-07-30 15:41:00 【Huo Hongpeng】
Register conventions

Preserved across calls?
字面意思是Preserve across calls,什么意思呢,也就是标记为YES的寄存器,It needs to remain unchanged before and after the subroutine is executed.如何做到这一点呢,That's where the subroutine uses theseYESbefore deposit,These registers need to be pushed onto the stack,The values of these registers are restored from the stack after use.
标记为NO的呢,It doesn't care when the subroutine is executed,如果NO寄存器,Subroutines are not desired(callee)before and after execution are changed,That requires the caller of the program(caller)Push the stack before the subroutine is executed,After the subroutine is executed, pop the stack to restore the register value.
总结:标记为YES的需要callee保存(Subroutines are saved by themselves),标记为NO的需要caller保存(调用者保存).
注意:
The way to keep the register value unchanged is not necessarily the only way to push and pop the stack,比入SP是
YESHold after subroutine callSP的值不变,Then you can put it at the beginning of the subroutine
SP减去一个值,at the end of the subroutineSP加上一个值,Keep the pre- and post-call unchanged.As shown in the following program fragment
示例:
(gdb) disass main
Dump of assembler code for function main:
0x0000000000010158 <+0>: addi sp,sp,-32 #Open up the stack size here
0x000000000001015a <+2>: sd ra,24(sp)
0x000000000001015c <+4>: sd s0,16(sp)
0x000000000001015e <+6>: addi s0,sp,32
0x0000000000010160 <+8>: li a5,1
0x0000000000010162 <+10>: sw a5,-20(s0)
0x0000000000010166 <+14>: li a5,2
0x0000000000010168 <+16>: sw a5,-24(s0)
0x000000000001016c <+20>: lw a4,-20(s0)
0x0000000000010170 <+24>: lw a5,-24(s0)
0x0000000000010174 <+28>: addw a5,a5,a4
0x0000000000010176 <+30>: sw a5,-28(s0)
0x000000000001017a <+34>: lw a5,-28(s0)
0x000000000001017e <+38>: mv a1,a5
0x0000000000010180 <+40>: lui a5,0x1c
0x0000000000010182 <+42>: addi a0,a5,176 # 0x1c0b0
0x0000000000010186 <+46>: jal ra,0x10332 <printf>
0x000000000001018a <+50>: li a5,0
0x000000000001018c <+52>: mv a0,a5
0x000000000001018e <+54>: ld ra,24(sp)
0x0000000000010190 <+56>: ld s0,16(sp)
0x0000000000010192 <+58>: addi sp,sp,32 #Restore after use
0x0000000000010194 <+60>: ret
End of assembler dump.
边栏推荐
猜你喜欢
随机推荐
Redis 缓存穿透、击穿、雪崩以及一致性问题
我们公司用了 6 年的网关服务,动态路由、鉴权、限流等都有,稳的一批!
websocket flv 客户端解封包
flask获取post请求参数
B+树索引页大小是如何确定的?
微服务架构下的核心话题 (二):微服务架构的设计原则和核心话题
golang图片处理库image简介
tiup help
本地事务与分布式事务
How to split microservices?
952. 按公因数计算最大组件大小 : 枚举质因数 + 并查集运用题
Office Automation | Office Software and Edraw MindMaster Shortcuts
L2-007 家庭房产(vector、set、map的使用)
Installing and Uninstalling MySQL on Mac
Lock wait timeout exceeded solution
让人上瘾的新一代开发神器,彻底告别Controller、Service、Dao等方法
科研中一些常用软件清单
华为「天才少年」计划招募的博士们,迎来首秀!
视频加密的误解
QIIME2得到PICRUSt2结果后如何分析









