1.1 传送指令
push %ebp
mov %esp,%ebp
and $0xfffffff0,%esp
//边界对齐指令,16字节对齐sub $0x20,%esp
movl $0xa,0x10(%esp)
//立即数10赋值给偏移量为
0x10的基址寄存器espmovl $0x9,0x14(%esp)
//立即数9赋值mov 0x10(%esp),%eax
mov %eax,0x18(%esp)
//立即数10赋值给0x18(%esp)mov 0x14(%esp),%eax
mov %eax,0x1c(%esp)
//立即数9赋值给0x1c(%esp)mov 0x1c(%esp),%eax
mov %eax,0x8(%esp)
//立即数9赋值给0x8(%esp)
mov 0x18(%esp),%eax
mov %eax,0x4(%esp)
//立即数10赋值给0x4(%esp)
movl $0x0,(%esp)
call 41 <main+0x41>
leave
ret
参考代码:
#include"stdio.h"
int main(){
int a,b,c,d;
a=10,b=9;
printf("评测结果:成功\n评测脚本:C\n返回结果:");//此行不在汇编代码中
//**********Begin**********
c=a;
d=b;
//**********End**********
printf("%d,%d\n",c,d);
}
1.2 传送指令
mov %esp,%ebp
and $0xfffffff0,%esp
sub $0x20,%esp
movl $0xa,0x18(%esp)
//立即数10赋值给偏移量为
0x18的基址寄存器espmov 0x18(%esp),%eax
mov %eax,0x1c(%esp)
mov 0x1c(%esp),%eax
mov %eax,0x8(%esp)
//立即数10赋值给``0x8(%esp)
mov 0x18(%esp),%eax
mov %eax,0x4(%esp)
movl $0x0,(%esp)
call 31 <main+0x31>
leave
ret
参考代码:
#include"stdio.h"
int main(){
int a=10;
int b;
printf("评测结果:成功\n评测脚本:C\n返回结果:");//此行不在汇编代码中
//**********Begin********
b=a;
printf("%d,%d\n",a,b);
//**********End**********
}
2.1 加减运算指令
push %ebp
mov %esp,%ebp
and $0xfffffff0,%esp
sub $0x20,%esp movl
movl $0x6,0x10(%esp)
//立即数6赋值给偏移量为
0x10的基址寄存器espmovl $0x64,0x14(%esp)
//16进制 立即数为100mov 0x14(%esp),%eax
mov 0x10(%esp),%edx
sub %eax,%edx
//将edx-eax的值赋值给edxmov %edx,%eax
mov %eax,0x18(%esp)
//将edx的值赋值给cmov 0x14(%esp),%eax
mov 0x10(%esp),%edx
add %edx,%eax
//将eax+edx的值赋值给edxmov %eax,0x1c(%esp)
mov 0x1c(%esp),%eax
mov %eax,0x8(%esp)
//将eax的值赋值给cmov 0x18(%esp),%eax
mov %eax,0x4(%esp)
movl $0x0,(%esp)
call 4f <main+0x4f>
leave
ret
参考代码 :
#include"stdio.h"
int main(){
int a,b,c,d;
a=6,b=100;
printf("评测结果:成功\n评测脚本:C\n返回结果:");//此行不在汇编代码中
//**********Begin**********
c=a-b;
d=a+b;
//**********End**********
printf("%d,%d\n",c,d);
}
3.1 整数的乘法指令
push %ebp
mov %esp,%ebp
and $0xfffffff0,%esp
sub $0x20,%esp
movl $0x3,0x10(%esp)
//立即数3赋值给偏移量为
0x10的基址寄存器espmov 0x10(%esp),%eax
sub $0x1,%eax
//将eax的值-1赋给eaximul 0x10(%esp),%eax
//将eax与0x10(%esp)内的值相乘赋给eaxmov %eax,0x14(%esp)
//赋值给bmov 0x10(%esp),%eax
imul 0x14(%esp),%eax
//将c与0x10(%esp)内的值相乘赋给eaxmov %eax,0x18(%esp)
//赋给cmov 0x18(%esp),%eax
add $0x2,%eax
//d+2的值赋给eaximul 0x10(%esp),%eax
//eax与0x10(%esp)内的值相乘赋给eaxmov %eax,0x1c(%esp)
//赋给dmov 0x1c(%esp),%eax
mov %eax,0x8(%esp)
//赋给dmov 0x18(%esp),%eax
mov %eax,0x4(%esp)
movl $0x0,(%esp)
call 56 <main+0x56>
leave
ret
参考代码:
#include"stdio.h"
int main(){
int a,b,c,d;
a=3;
printf("评测结果:成功\n评测脚本:C\n返回结果:");//此行不在汇编代码中
//**********Begin**********
b=a*(a-1);
c=a*b;
d=a*(c+2);
//**********End**********
printf("%d,%d\n",c,d);
}
4.1 控制转移指令
00000000 <sum>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 10 sub $0x10,%esp
//分配十字节空间6: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
//s =0d: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp)
//i =014: eb 18 jmp 2e <sum+0x2e>
16: 8b 45 f8 mov -0x8(%ebp),%eax
//19: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx
//a[i]的值赋给edx20: 8b 45 08 mov 0x8(%ebp),%eax
//23: 01 d0 add %edx,%eax
25: 8b 00 mov (%eax),%eax
27: 01 45 fc add %eax,-0x4(%ebp)
//s的值+a[i]赋给s2a: 83 45 f8 01 addl $0x1,-0x8(%ebp)
//i的值+1赋给i2e: 8b 45 f8 mov -0x8(%ebp),%eax
//i的值赋给eax31: 3b 45 0c cmp 0xc(%ebp),%eax
//比较i跟n的值;34: 7c e0 jl 16 <sum+0x16>
36: 8b 45 fc mov -0x4(%ebp),%eax
39: c9 leave
3a: c3 ret
参考代码:
#include"stdio.h"
int sum(int a[],int n){
//**********Begin**********
int s = 0;
for (int i = 0;i<n; i++) {
s += a[i];
}
return s;
//**********End**********
}