使用多个mips参数> 4 [英] using multiple mips arguments >4

查看:173
本文介绍了使用多个mips参数> 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过将函数压入堆栈来编程一个函数以使用除4以外的其他参数(因为我的mips版本仅支持$ a0- $ a3),但是我的代码不正确.这是我的主要代码段中的代码:

Im trying to program a function to use extra arguments besides 4 (since my version of mips only supports $a0-$a3) by pushing them on the stack, but my code is incorrect. Here is my code in main (snippet):

li $t0,40 #temp value for our 5th arg.

addi $sp, $sp, -4 #decrement stack pointer by 4
sw $t0, 0($sp) #save the value of $t0 on the stack.

jal printf

将临时值设置为40,在堆栈上留出空间并保存.然后调用我的函数.作为测试是否可行的测试,当我将这些临时参数$ a0- $ a3移至已保存的寄存器副本时,在函数内部,我有以下代码:

which sets a temporary value of 40, gives space on the stack, and saves it. My function is then called. As a test to see if this worked, inside the function when i move these temp arguments $a0-$a3 to their saved register counterparts, I have this code:

lw $t0, 0($sp) 
addi $sp, $sp, 4
move $a0,$t0

li $v0, 1
syscall

...但是它只打印出0而不是40,所以我做错了什么.任何帮助将不胜感激(并赞成)

...but it only prints out a 0 and not 40, so im doing something incorrect. Any help would be greatly appreciated (and upvoted)

推荐答案

在最常见的32位MIPS中调用约定$a0,$a1,$a2$a3在堆栈上保留了空间,因此被调用函数应该期望在16($sp)处找到第5个参数.

In the most common 32 bit MIPS calling convention, space is reserved on the stack for $a0,$a1,$a2 and $a3, so the called function should expect to find the 5th argument at 16($sp).

弄清楚这些事情的最简单方法是在C语言中编写函数的空版本,并反汇编.o文件以弄清楚编译器如何传递参数.

The easiest way to figure these things out is to write an empty version of your function in C, and dissassemble the .o file to figure out how the arguments are passed by the compiler.

这篇关于使用多个mips参数> 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆