当前位置:网站首页>RISC-V调用惯例
RISC-V调用惯例
2022-07-30 14:48:00 【霍宏鹏】
寄存器惯例

Preserved across calls?
字面意思是跨调用保留,什么意思呢,也就是标记为YES的寄存器,需要在子程序执行前后保持不变。如何做到这一点呢,那就是子程序使用这些YES寄存之前,需要把这些寄存器压栈,用完以后从栈中恢复这些寄存器的值。
标记为NO的呢,子程序执行的时候是不关心的,如果NO寄存器,不希望子程序(callee)执行前后被改变,那就需要程序的调用者(caller)在子程序执行前压栈,子程序执行后出栈恢复寄存器值。
总结:标记为YES的需要callee保存(子程序自己保存),标记为NO的需要caller保存(调用者保存)。
注意:
保持寄存器值不变的方式不一定只有入栈和出栈,比入SP是
YES子程序调用后保持SP的值不变,那么可以在子程序的开始把
SP减去一个值,在子程序的最后把SP加上一个值,保持调用前后不变。如下面程序片段所示
示例:
(gdb) disass main
Dump of assembler code for function main:
0x0000000000010158 <+0>: addi sp,sp,-32 #在这里开辟栈大小
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 #用完以后恢复
0x0000000000010194 <+60>: ret
End of assembler dump.
边栏推荐
- 2022最新 | 室外单目深度估计研究综述
- Flink optimization
- 软件包 - 笔记
- 三电系统集成技术杂谈
- MongoDB starts an error Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
- 元宇宙的前景及四大赛道
- MySQL客户端工具的使用与MySQL SQL语句
- LeetCode_数位枚举_困难_233.数字 1 的个数
- The highest level of wiring in the computer room, the beauty is suffocating
- Alluxio为Presto赋能跨云的自助服务能力
猜你喜欢

Smart Contract Security - Private Data Access

timed task corn

71-page comprehensive overall solution for global tourism 2021 ppt

canal scrape data

Alluxio for Presto fu can across the cloud self-service ability

华为再发「天才少年」召集令!曾放弃360万年薪的他也来首秀

How do luxury giants such as GUCCI and LV deploy the metaverse, should other brands keep up?

使用 protobuf 进行数据序列化

组态 - 笔记

5G-based Warehousing Informatization Solution 2022
随机推荐
In-depth analysis of Kubernetes application management
websocket flv 客户端解封包
golang modules initialization project
阿里CTO程立:阿里巴巴的开源历程、理念和实践
(Crypto essential dry goods) Detailed analysis of the current NFT trading markets
微服务该如何拆分?
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
Delayed message queue
剑指 Offer II 037. 小行星碰撞
组态 - 笔记
数据库日期类型字段设计,应该如何选择?
Nature Microbiology综述:聚焦藻际--浮游植物和细菌互作的生态界面
[In-depth study of 4G/5G/6G topic-46]: 5G Link Adaption Link Adaption-2-Common Abbreviations
GUCCI、LV等奢侈品巨头如何布局元宇宙的,其他品牌应该跟上吗?
MongoDB启动报错 Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
MySql报错:SqlError(Unable to execute query“, “Can‘t create/write to file OS errno 2 - No such file...
MySQL客户端工具的使用与MySQL SQL语句
Office Automation | Office Software and Edraw MindMaster Shortcuts
Normal and escaped strings for postgresql
Redis 缓存穿透、击穿、雪崩以及一致性问题