看明白了一段mips汇编


今天总算看明白了网上一段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: Why we fill the second argument 
*behind the addFunc function call? 
* This is all about the "-O1" compilation optimizaiton. 
* With mips architecture, the instruciton after jump 
* will also be fetched into the pipline and get 
* exectuted. Therefore, we can promise that the 
* second argument will be filled with the value of 
* integer 2. 
*/ 
18: 24050002 li $a1,2 
/*Load the return address from the stack pointer 
* Note here that the result v0 contains the result of 
* addFunc function call 
*/ 
1c: 8fbf0000 lw $ra,0($sp) 
/* Return */ 
20: 03e00008 jr $ra 
/* Restore the stack frame */ 
24: 27bd0008 addiu $sp,$sp,8 

/* addFunc Function */ 
0000000000000028 : 
/* Create a stack frame by allocating 16 bytes or 4 
* words size 
*/ 
28: 27bdfff0 addiu $sp,$sp,-16 
/* Save the return address into the stack with 8 bytes 
* offset. Please note that compiler does not save the 
* ra to 0($sp). 
*Think of why, in contrast of the previous PowerPC 
* EABI convention 
*/ 
2c: afbf0008 sw $ra,8($sp) 
/* We save the s1 reg. value into the stack 
* because we will use s1 in this function 
* Note that the 4,5,6,7($sp) positions will then 
* be occupied by this 32 bits size register 
*/ 
30: afb10004 sw $s1,4($sp) 
/* Withe same reason, save s0 reg. */ 
34: afb00000 sw $s0,0($sp) 
/* Retrieve the argument 0 into s0 reg. */ 
38: 0080802d move $s0,$a0 
/* Retrieve the argument 1 into s1 reg. */ 
3c: 00a0882d move $s1,$a1 
/* Call the subFunc with a0 with 5 */ 
40: 0c000019 jal 64 
/* In the delay slot, we load the 5 into argument a0 reg 
*for subFunc call. 
*/ 
44: 24040005 li $a0,5 
/* s0 = s0+s1; note that s0 and s1 holds the values of 
* x,y, respectively 
*/ 
48: 02118021 addu $s0,$s0,$s1 
/* v0 = s0+v0; v0 holds the return results of subFunc 
*call; And we let v0 hold the final results 
*/ 
4c: 02021021 addu $v0,$s0,$v0 
/*Retrieve the ra value from stack */ 
50: 8fbf0008 lw $ra,8($sp) 
/*!!!!restore the s1 reg. value */ 
54: 8fb10004 lw $s1,4($sp) 
/*!!!! restore the s0 reg. value */ 
58: 8fb00000 lw $s0,0($sp) 
/* Return back to main func */ 
5c: 03e00008 jr $ra 
/* Update/restore the stack pointer/frame */ 
60: 27bd0010 addiu $sp,$sp,16 

/* subFunc Function */ 
0000000000000064 : 
/* return back to addFunc function */ 
64: 03e00008 jr $ra 
/* Taking advantage of the mips delay slot, filling the 
* result reg v0 by simply assigning the v0 as the value 
*of a0. This is a bug from my c source 
* codes--"value--". I should write my codes 
* like "--value", instead. 
68: 0080102d move $v0,$a0

为便于察看,我已经将指令全部高亮为蓝色。如果对MIPS指令不熟,看起来还是比较废劲的哦。我是对着指令解释,并画图,废了九牛二虎之力阿。搞懂后,有种毛塞顿开,总算打开门之感,颇为爽!.^_^偶正致力于往底层驱动发展,此番进步亦算是鼓励了。忘高手或者有心往此方面发展的朋友,多多交流哦。

汇编带符号表的32位/64位ELF目标文件,CPU类型:ARM PowerPC MIPS 操作菜单选择:文件解析 Alx+P ELF文件解析 Alt+E 另有文本比较等杂项功能。V1.25.00相对上一版本,相关功能支持动态库文件,查询代码支持无符号目标文件+有符号目标文件,COREDUMP统计、与问题单关联、目标文件/CORE文件/问题单同步;V1.24.02相对上一版本,针对进程主动捕捉异常的信息定制处理进一步完善COREDUMP文件解析与应用,增强软件管理;V1.24.01相对上一版本,进一步完善COREDUMP文件解析与应用,提供部分ARM Thumb指令反汇编;V1.24.00相对上一版本,进一步完善COREDUMP文件解析与应用,提供堆栈调用关系分析;V1.23.03相对上一版本,提供32位X86反汇编;V1.23.02相对上一版本,提供源代码行查询指令地址,OBJ/COREDUMP文件解析,sprintf函数参数特定检查,完善文件拖放操作,修复小BUG;V1.23.01相对上一版本,提供ELF文件指令修改,修复ARM MLS指令反汇编错误等BUG;V1.23.00相对上一版本,提供程序地址对应源代码行查询,修复MIPS调试信息错误;V1.22相对上一版本,修复MIPS小端字节序反汇编错误,网上最新版本提示;V1.21相对上一版本,菜单调整,完善64位ELF文件解析,解析调试信息;另部分增强功能的菜单操作设有密码,如有兴趣欢迎咨询。欢迎大家反馈相关软件使用过程中的问题!
汇编带符号表的32位/64位ELF目标文件,CPU类型:ARM PowerPC MIPS X86 操作菜单选择:文件解析 Alx+P ELF文件解析 Alt+E 另有文本比较等杂项功能。V1.26.00相对上一版本,增强EXE反汇编,增加dbx老邮件解析、二维码功能,;V1.25.07相对上一版本,增加二进制反汇编、IQ数据解析功能,完善MIPS汇编,修复小BUG;V1.25.05相对上一版本,增加内存数据按数据类型解析功能;V1.25.04相对上一版本,完善X86反汇编,修复小BUG;V1.25.02相对上一版本,COREDUMP统计、匹配目标文件等相关功能优化,修复小BUG;V1.25.00相对上一版本,相关功能支持动态库文件,查询代码支持无符号目标文件+有符号目标文件,COREDUMP统计、与问题单关联、目标文件/CORE文件/问题单同步;V1.24.02相对上一版本,针对进程主动捕捉异常的信息定制处理进一步完善COREDUMP文件解析与应用,增强软件管理;V1.24.01相对上一版本,进一步完善COREDUMP文件解析与应用,提供部分ARM Thumb指令反汇编;V1.24.00相对上一版本,进一步完善COREDUMP文件解析与应用,提供堆栈调用关系分析;V1.23.03相对上一版本,提供32位X86反汇编;V1.23.02相对上一版本,提供源代码行查询指令地址,OBJ/COREDUMP文件解析,sprintf函数参数特定检查,完善文件拖放操作,修复小BUG;V1.23.01相对上一版本,提供ELF文件指令修改,修复ARM MLS指令反汇编错误等BUG;V1.23.00相对上一版本,提供程序地址对应源代码行查询,修复MIPS调试信息错误;V1.22相对上一版本,修复MIPS小端字节序反汇编错误,网上最新版本提示;V1.21相对上一版本,菜单调整,完善64位ELF文件解析,解析调试信息;另部分增强功能的菜单操作设有密码,如有兴趣欢迎咨询。欢迎大家反馈相关软件使用过程中的问题!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值