当前位置:网站首页>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.
边栏推荐
- 视频加密的误解
- The evolution of content products has three axes: traffic, technology, and product form
- 【元胞自动机】基于元胞自动机模拟生命演化、病毒感染等实例附matlab代码
- Huawei issues another summoning order for "Genius Boys"!He, who had given up an annual salary of 3.6 million, also made his debut
- 华为再发「天才少年」召集令!曾放弃360万年薪的他也来首秀
- MASM32v11编程调用Process32First失败: 程序发出命令,但命令长度不正确
- What is Ts?
- 【回归预测-CNN预测】基于卷积神经网络CNN实现数据回归预测附matlab代码
- 超T动力 盈运天下——中国重汽黄河/豪沃WP14T产品首发荣耀上市!
- Use of InputStream and OutputStream
猜你喜欢

Flink本地UI运行

English语法_不定代词 - both / either / neither

面试何惧调优!腾讯技术官私藏的性能优化方案手册,原理实战齐全

Delayed message queue

定时任务 corn

MongoDB starts an error Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)

基于FPGA的DDS任意波形输出

This editor actually claims to be as fast as lightning!
4 senior experts share the insider architecture design and implementation principles of Flink technology with years of experience in large factories

自动化办公|办公软件和亿图脑图MindMaster快捷键
随机推荐
Flink实时仓库-DWS层(状态编程,windowall的使用,数据保存到clickhouse)模板代码
华为无线设备Mesh配置命令
Office Automation | Office Software and Edraw MindMaster Shortcuts
视频切换播放的例子(视频切换范例)代码
MongoDB starts an error Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
Huawei issues another summoning order for "Genius Boys"!He, who had given up an annual salary of 3.6 million, also made his debut
GUCCI、LV等奢侈品巨头如何布局元宇宙的,其他品牌应该跟上吗?
71页全域旅游综合整体解决方案2021 ppt
机房布线的至高境界,美到窒息
微服务该如何拆分?
[In-depth study of 4G/5G/6G topic-46]: 5G Link Adaption Link Adaption-2-Common Abbreviations
【云原生】灰度发布、蓝绿发布、滚动发布、灰度发布解释
这个编辑器居然号称快如闪电!
timed task corn
本地事务与分布式事务
元宇宙的前景及四大赛道
算力顶天地,存力纳乾坤:国家超级计算济南中心的一体两面
MongoDB starts an error Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
怎么判断两个字符串是否相等?
编译、链接 - 笔记 - 3