c语⾔中mipsjal指令,看明⽩了⼀段mips汇编正 ⽂
看明⽩了⼀段mips汇编(2006/4/29 15:34)
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;
汇编table指令什么意思
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指令不熟,看起来还是⽐较废劲的哦。我是对着指令解释,并画图,废了九⽜⼆虎之⼒阿。搞懂后,有种⽑塞顿开,总算打开门之感,颇为爽!.^_^偶正致⼒于往底层驱动发展,此番进步亦算是⿎励了。忘⾼⼿或者有⼼往此⽅⾯发展的朋友,多多交流哦。
评 论
12楼 hdguy 发表于 2007/12/11 13:47 回复
不好意思,很久没有看MIPS了,不少都忘记了。
11楼 tjh(游客) 发表于 2007/9/24 11:08 回复
******这是⼀个Reset.S启动代码⽂件帮忙分析⼀下********** LEAF(__reset_vector) .set noreorder MFC0( t0, C0_PRId) lit1,
M_PRIdImp | M_PRIdCoID and t0, t1 lit1, PRID_IMP_4Kec | PRID_COMP_MIPS beqt1, t0, is_4Kec nop li t1, 0x1000; 1: addiu t1, -1 bne t1, zero, 1b nop lat0, av_entry jalrt0 /*5280 will auto flush cache after reset */ nop is_4Kec: /* set EJ_TDO to
4mA , for ICE help*/ lwt0,0xb801a150 ; or t0, 0x4; sw t0, 0xb801a150; /* Clear watch registers */ MTC0(zero,
C0_WatchLo) MTC0(zero, C0_WatchHi) /* Disable interrupts and KSU field (power up issue) */ MFC0( k0, C0_Status) lik1, ~ (M_StatusIE | M_StatusKSU) andk0, k1 MTC0(k0, C0_Status) 1: lik1, KSEG1BASE lak0, _reset_handler_le /* Defined in linker script */ ork0, k1/* Make sure it is uncached */ jrk0 nop /*cy test */ error: 1: b 1b nop .org 0x200 1:b1b/* Stay here */ nop .org 0x280 1:b1b/* Stay here */ nop .org 0x300 1:b1b/* Stay here */ nop .org 0x380 li t1, 0x49; sw t1, 0xb801b200; 1:/* Stay here */ b 1b nop .org 0x400 1:b1b/* Stay here */ nop .org 0x480 mtc0 v0, C0_DESAVE li v0,
KSEG0(SYS_EJTAG_RAM_VECTOR_OFS) jrv0 mfc0 v0, C0_DESAVE .org 0x500 /* 0xBFC00500 Vector table for shell functions */ END(__reset_vector)
10楼 warrior(游客) 发表于 2007/4/23 14:03 回复
另外。。。 这段 4: afbf0000 sw $ra,0($sp) 8: 0c000000 jal 0 /* nop is for the delay slot */ c: 00000000 nop 怎么⼜JAL回前⾯的0地址了。。。。。。
9楼 warrior(游客) 发表于 2007/4/23 09:42 回复
兄弟~我也想要份MIPS汇编指令的⽂档,我⽬前是做底层和BSP开发,前⾯⼏个⽉做的是ARM9的,下⼀个项⽬⽤的是MIPS的,所以想提前准备点知识 EMAIL: [email protected] 多谢了
8楼 hdguy 发表于 2007/1/22 10:12 回复
TO crystal: 1c: 8fbf0000 lw $ra,0($sp) 举这个例⼦来说,前⾯的1C就是指令的地址了,8fbf0000应该就是后⾯的汇编指令的⼆进制编码,有兴趣的话,你可以仔细核对⼀下,看是不是
7楼 hdguy 发表于 2007/1/22 10:10 回复
不好意思,那些反汇编后的信息很多我也不知道什么意思。应该是编译器提供的⼀些关于各种代码段什么的说明,这个可能需要具体的编译器和汇编器说明了
6楼 crystal(游客) 发表于 2007/1/19 16:02 回复
你好,我将MIPS的⼆进制⽂件进⾏反汇编,发现除了主函数外还有很多其它的信息,这些信息分别都是什么内容。望交流~~~~~~~~~~~~~~~ xinru0199◎sina
5楼 Robin(游客) 发表于 2006/11/16 13:42 回复
给我⼀份mips汇编指令集⽂档吧,谢谢 pooli*163 *替换为@ 谢谢~
4楼 hdguy 发表于 2006/8/30 11:07 回复
这些资料都可以到⽹上得到的,如有需要你可以留下email
3楼 张贤义(游客) 发表于 2006/8/20 10:18 回复
请问你有MIPS指令的解释⽂档吗?
我现在看操作系统,学习使⽤nachos, 源代码中有部分
是MIPS汇编代码,指令看不明⽩。
联系QQ:20558641

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。