当前位置:网站首页>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.
边栏推荐
猜你喜欢

组态 - 笔记

canal抓取数据

使用 protobuf 进行数据序列化

Metaverse Post Office AI space-themed series of digital collections will be launched at 10:00 on July 30th "Yuanyou Digital Collection"

71页全域旅游综合整体解决方案2021 ppt

Extremely Knowing v2 Analysis

极验深知v2分析

我们公司用了 6 年的网关服务,动态路由、鉴权、限流等都有,稳的一批!

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

Sentinel
随机推荐
Memory-mapped, bit-band operations
组态 - 笔记
GUCCI、LV等奢侈品巨头如何布局元宇宙的,其他品牌应该跟上吗?
存储器映射、位带操作
English语法_不定代词 - both / either / neither
QIIME2得到PICRUSt2结果后如何分析
MongoDB启动报错 Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
v-model组件化编程应用
MaxWell scraped data
How do luxury giants such as GUCCI and LV deploy the metaverse, should other brands keep up?
Lock wait timeout exceeded解决方案
[Cloud Native] Service Industry Case - Solutions for Unpredictable Concurrency Scenarios
Kubernetes应用管理深度剖析
Redis cache penetration, breakdown, avalanche and consistency issues
TensorFlow自定义训练函数
How is the B+ tree index page size determined?
The highest level of wiring in the computer room, the beauty is suffocating
去腾讯面试,直接让人出门左拐 :幂等性都不知道!
Introduction to golang image processing library image
华为再发「天才少年」召集令!曾放弃360万年薪的他也来首秀