我有一个C
代码,可以交换两个数字。
#include<stdio.h>
void swap(int,int);
void main( )
{
int n1,n2;
printf("Enter the two numbers to be swapped\n");
scanf("%d%d",&n1,&n2);
printf("\nThe values of n1 and n2 in the main function before calling the swap function are n1=%d n2=%d",n1,n2);
swap(n1,n2);
printf("\nThe values of n1 and n2 in the main function after calling the swap function are n1=%d n2=%d",n1,n2);}
void swap(int n1,int n2)
{
int temp;
temp=n1;
n1=n2;
n2=temp;
printf("\nThe values of n1 and n2 in the swap function after swapping are n1=%d n2=%d",n1,n2);
}
我已使用objdump
对其进行了拆解,并试图找出交换操作在计算机级别如何发生。我认为这是交换功能。
000006b4 <swap>:
6b4: 55 push %ebp
6b5: 89 e5 mov %esp,%ebp
6b7: 53 push %ebx
6b8: 83 ec 14 sub $0x14,%esp
6bb: e8 37 00 00 00 call 6f7 <__x86.get_pc_thunk.ax>
6c0: 05 0c 19 00 00 add $0x190c,%eax
6c5: 8b 55 08 mov 0x8(%ebp),%edx
6c8: 89 55 f4 mov %edx,-0xc(%ebp)
6cb: 8b 55 0c mov 0xc(%ebp),%edx
6ce: 89 55 08 mov %edx,0x8(%ebp)
6d1: 8b 55 f4 mov -0xc(%ebp),%edx
6d4: 89 55 0c mov %edx,0xc(%ebp)
6d7: 83 ec 04 sub $0x4,%esp
6da: ff 75 0c pushl 0xc(%ebp)
6dd: ff 75 08 pushl 0x8(%ebp)
6e0: 8d 90 c0 e8 ff ff lea -0x1740(%eax),%edx
6e6: 52 push %edx
6e7: 89 c3 mov %eax,%ebx
6e9: e8 72 fd ff ff call 460 <printf@plt>
6ee: 83 c4 10 add $0x10,%esp
6f1: 90 nop
6f2: 8b 5d fc mov -0x4(%ebp),%ebx
6f5: c9 leave
6f6: c3 ret
我想知道寄存器内的交换操作是如何发生的,我知道它必须是这样的。
push eax
mov eax, ebx
pop ebx
但是我看不到任何类似的东西。由于我是新手,所以有人可以帮助我如何了解情况如何。 Full output of the objdump
is here.
答案 0 :(得分:1)
要开始使用汇编语言,您可以检查以下链接:
http://patshaughnessy.net/2016/11/26/learning-to-read-x86-assembly-language