正 文
看明白了一段mips汇编(2006/4/29 15:34)
今天总算看明白了网上一段mips汇编代码,感觉很爽阿,呵呵,只是让大虾见笑了。原文章(包含该代码)在如下网址:http://www.xtrj.org/mips/, 题目是MIPS体系结构剖析,编程与实践(作者:张福新,陈怀临, 2002)
C代码如下:
~/ vi Hello.c
"Hello.c" [New file]
/* Example to illustrate mips register convention
* -Author: BNN
* 11/29/2001
*/
int addFunc(int,int);
int subFunc(int);
void main()
{
int x,y,z;
x= 1;
y=2;
z = addFunc(x,y);
}
int addFunc(int x,int y)
{
int value1 = 5;
int value2;
value2 = subFunc(value1);
return (x+y+value2);
}
int subFunc(int value)
{
return value--;
}
反汇编代码后的代码:
/* main Function */
0000000000000000 :
/*create a stack frame by moving the stack pointer 8
*bytes down and meantime update the sp value
*/
0: 27bdfff8 addiu $sp,$sp,-8/* Save the return address to the current sp position.*/
4: afbf0000 sw $ra,0($sp)
8: 0c000000 jal 0 /* nop is for the delay slot */
c: 00000000 nop
/* Fill the argument a0 with the value 1 */
10: 24040001 li $a0,1
/* Jump the addFunc */
14: 0c00000a jal 28/* NOTE HERE: Wh