当前位置:网站首页>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 theseYES
before 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是
YES
Hold 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.
边栏推荐
猜你喜欢
随机推荐
【云原生】服务行业案例-不可预测的并发场景解决方案
[Cloud native] Grayscale release, blue-green release, rolling release, grayscale release explanation
Redis cache penetration, breakdown, avalanche and consistency issues
使用 TiUP 命令管理组件
关于mariadb/mysql的user表:密码正确但登录失败,可能与mysql的空用户有关
B+树索引页大小是如何确定的?
QIIME2得到PICRUSt2结果后如何分析
【为宏正名】99%的人从第一天学习C语言就自废的武功
Store Limit 使用文档
Excel uses Visual Basic Editor to modify macros
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
针对 MySQL/InnoDB 刷盘调优
被捧上天的Scrum敏捷管理为何不受大厂欢迎了?
RISC-V调用惯例
Huawei issues another summoning order for "Genius Boys"!He, who had given up an annual salary of 3.6 million, also made his debut
Alluxio为Presto赋能跨云的自助服务能力
90后人大硕士为学医竟重新高考,成功被首医大录取
工具| execsnoop 短时进程追踪工具
L2-007 家庭房产(vector、set、map的使用)
MySql报错:SqlError(Unable to execute query“, “Can‘t create/write to file OS errno 2 - No such file...