Linux-C strlen()与sizeof

Linux-C strlen()与sizeof

一、简述

    strlen()函数一般用来获取字符串的长度,不包括'\0';sizeof 操作符用来获取类型占用的字节数或常量占用的字节数,包括'\0'。

     其实strlen()函数可以看为:传递一个地址进去,一个一个字节解析,不是'\0'就长度加1,遇到'\0'就结束。

二、strlen()函数

    所需头文件为:string.h

    示例代码:

#include 
#include 


int main(int argc,char* argv[])
{

	char* p_ch = "hello";
	char ch_arr[] = "hello";
	
	printf("p:%d \n",strlen(p_ch));
	printf("ch_arr:%d \n",strlen(ch_arr));//但是数组的长度是6,包含了'\0'
	printf("hello:%d \n",strlen("hello"));
	
	return 0;
}

 

    代码结果:

 

Linux-C strlen()与sizeof_第1张图片

自己尝试简单写strlen()函数

#include 


int strlen(const char * str);//函数声明

int main(int argc,char* argv[])
{
	
	char* p_ch = "hello";
	char ch_arr[] = "hello";

	printf("p:%d \n",strlen(p_ch));
	printf("ch_arr:%d \n",strlen(ch_arr));
	printf("hello:%d \n",strlen("hello"));
	return 0;
}



int strlen(const char * str)//const限定函数内部不能改变str
{
	int length = 0;
	while(str[length++]!='\n');
	return length;
}

代码结果:

Linux-C strlen()与sizeof_第2张图片

三、sizeof操作符:虽然"长"得像函数,但是它是操作符;在不引起歧义时它可以不用括号。

    示例代码:

#include 


int main(int argc,char* argv[])
{
	char ch = 'a';
	int num = 10;
	float fl= 1.23f;
	double db = 4.567;
	char* p_ch = "hello";
	char ch_arr[] = "hello";

	
	printf("10:%d \n",sizeof(10));
	printf("1.23f:%d \n",sizeof(1.23f));
	printf("4.567:%d \n\n",sizeof(4.567));


	printf("a:%d \n",sizeof(ch));
	printf("num:%d \n",sizeof(num));
	printf("fl:%d \n",sizeof(fl));
	printf("db:%d \n\n",sizeof(db));

	printf("char:%d \n",sizeof(char));
	printf("int:%d \n",sizeof(int));
	printf("float:%d \n",sizeof(float));
	printf("double:%d \n\n",sizeof(double));

	printf("ch:%d \n",sizeof ch);
	printf("num:%d \n",sizeof num);
	printf("fl:%d \n",sizeof fl);
	printf("db:%d \n\n",sizeof db);

	printf("p_ch:%d \n",sizeof(p_ch));
	printf("ch_arr:%d \n",sizeof(ch_arr));
	printf("hello:%d \n",sizeof("hello"));

	return 0;
}

 

    代码结果:

 

Linux-C strlen()与sizeof_第3张图片

 

        注:指针变量占用字节一般由系统(CPU寻址范围)决定,在32位系统中一般是4字节。

sizeof操作符是编译阶段就完成计算的的,即还没有运行程序就完成了,或者是说用结果4代替sizeof(int),更不会向函数那样运行到才执行。

对sizeof.c文件只进行编译但比执行:执行gcc sizeof.c -o sizeof    生成sizeof可执行文件;

使用命令objdump -S sizeof 来查看sizeof文件。

Linux-C strlen()与sizeof_第4张图片

 

Disassembly of section .init:

080482f8 <_init>:
 80482f8:	53                   	push   %ebx
 80482f9:	83 ec 08             	sub    $0x8,%esp
 80482fc:	e8 00 00 00 00       	call   8048301 <_init+0x9>
 8048301:	5b                   	pop    %ebx
 8048302:	81 c3 f3 1c 00 00    	add    $0x1cf3,%ebx
 8048308:	8b 83 fc ff ff ff    	mov    -0x4(%ebx),%eax
 804830e:	85 c0                	test   %eax,%eax
 8048310:	74 05                	je     8048317 <_init+0x1f>
 8048312:	e8 49 00 00 00       	call   8048360 <__gmon_start__@plt>
 8048317:	e8 f4 00 00 00       	call   8048410 
 804831c:	e8 7f 03 00 00       	call   80486a0 <__do_global_ctors_aux>
 8048321:	83 c4 08             	add    $0x8,%esp
 8048324:	5b                   	pop    %ebx
 8048325:	c3                   	ret    

Disassembly of section .plt:

08048330 :
 8048330:	ff 35 f8 9f 04 08    	pushl  0x8049ff8
 8048336:	ff 25 fc 9f 04 08    	jmp    *0x8049ffc
 804833c:	00 00                	add    %al,(%eax)
	...

08048340 :
 8048340:	ff 25 00 a0 04 08    	jmp    *0x804a000
 8048346:	68 00 00 00 00       	push   $0x0
 804834b:	e9 e0 ff ff ff       	jmp    8048330 <_init+0x38>

08048350 <__stack_chk_fail@plt>:
 8048350:	ff 25 04 a0 04 08    	jmp    *0x804a004
 8048356:	68 08 00 00 00       	push   $0x8
 804835b:	e9 d0 ff ff ff       	jmp    8048330 <_init+0x38>

08048360 <__gmon_start__@plt>:
 8048360:	ff 25 08 a0 04 08    	jmp    *0x804a008
 8048366:	68 10 00 00 00       	push   $0x10
 804836b:	e9 c0 ff ff ff       	jmp    8048330 <_init+0x38>

08048370 <__libc_start_main@plt>:
 8048370:	ff 25 0c a0 04 08    	jmp    *0x804a00c
 8048376:	68 18 00 00 00       	push   $0x18
 804837b:	e9 b0 ff ff ff       	jmp    8048330 <_init+0x38>

Disassembly of section .text:

08048380 <_start>:
 8048380:	31 ed                	xor    %ebp,%ebp
 8048382:	5e                   	pop    %esi
 8048383:	89 e1                	mov    %esp,%ecx
 8048385:	83 e4 f0             	and    $0xfffffff0,%esp
 8048388:	50                   	push   %eax
 8048389:	54                   	push   %esp
 804838a:	52                   	push   %edx
 804838b:	68 90 86 04 08       	push   $0x8048690
 8048390:	68 20 86 04 08       	push   $0x8048620
 8048395:	51                   	push   %ecx
 8048396:	56                   	push   %esi
 8048397:	68 34 84 04 08       	push   $0x8048434
 804839c:	e8 cf ff ff ff       	call   8048370 <__libc_start_main@plt>
 80483a1:	f4                   	hlt    
 80483a2:	90                   	nop
 80483a3:	90                   	nop
 80483a4:	90                   	nop
 80483a5:	90                   	nop
 80483a6:	90                   	nop
 80483a7:	90                   	nop
 80483a8:	90                   	nop
 80483a9:	90                   	nop
 80483aa:	90                   	nop
 80483ab:	90                   	nop
 80483ac:	90                   	nop
 80483ad:	90                   	nop
 80483ae:	90                   	nop
 80483af:	90                   	nop

080483b0 <__do_global_dtors_aux>:
 80483b0:	55                   	push   %ebp
 80483b1:	89 e5                	mov    %esp,%ebp
 80483b3:	53                   	push   %ebx
 80483b4:	83 ec 04             	sub    $0x4,%esp
 80483b7:	80 3d 18 a0 04 08 00 	cmpb   $0x0,0x804a018
 80483be:	75 3f                	jne    80483ff <__do_global_dtors_aux+0x4f>
 80483c0:	a1 1c a0 04 08       	mov    0x804a01c,%eax
 80483c5:	bb 20 9f 04 08       	mov    $0x8049f20,%ebx
 80483ca:	81 eb 1c 9f 04 08    	sub    $0x8049f1c,%ebx
 80483d0:	c1 fb 02             	sar    $0x2,%ebx
 80483d3:	83 eb 01             	sub    $0x1,%ebx
 80483d6:	39 d8                	cmp    %ebx,%eax
 80483d8:	73 1e                	jae    80483f8 <__do_global_dtors_aux+0x48>
 80483da:	8d b6 00 00 00 00    	lea    0x0(%esi),%esi
 80483e0:	83 c0 01             	add    $0x1,%eax
 80483e3:	a3 1c a0 04 08       	mov    %eax,0x804a01c
 80483e8:	ff 14 85 1c 9f 04 08 	call   *0x8049f1c(,%eax,4)
 80483ef:	a1 1c a0 04 08       	mov    0x804a01c,%eax
 80483f4:	39 d8                	cmp    %ebx,%eax
 80483f6:	72 e8                	jb     80483e0 <__do_global_dtors_aux+0x30>
 80483f8:	c6 05 18 a0 04 08 01 	movb   $0x1,0x804a018
 80483ff:	83 c4 04             	add    $0x4,%esp
 8048402:	5b                   	pop    %ebx
 8048403:	5d                   	pop    %ebp
 8048404:	c3                   	ret    
 8048405:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
 8048409:	8d bc 27 00 00 00 00 	lea    0x0(%edi,%eiz,1),%edi

08048410 :
 8048410:	55                   	push   %ebp
 8048411:	89 e5                	mov    %esp,%ebp
 8048413:	83 ec 18             	sub    $0x18,%esp
 8048416:	a1 24 9f 04 08       	mov    0x8049f24,%eax
 804841b:	85 c0                	test   %eax,%eax
 804841d:	74 12                	je     8048431 
 804841f:	b8 00 00 00 00       	mov    $0x0,%eax
 8048424:	85 c0                	test   %eax,%eax
 8048426:	74 09                	je     8048431 
 8048428:	c7 04 24 24 9f 04 08 	movl   $0x8049f24,(%esp)
 804842f:	ff d0                	call   *%eax
 8048431:	c9                   	leave  
 8048432:	c3                   	ret    
 8048433:	90                   	nop

08048434 
: 8048434: 55 push %ebp 8048435: 89 e5 mov %esp,%ebp 8048437: 83 e4 f0 and $0xfffffff0,%esp 804843a: 83 ec 40 sub $0x40,%esp 804843d: 8b 45 0c mov 0xc(%ebp),%eax 8048440: 89 44 24 1c mov %eax,0x1c(%esp) 8048444: 65 a1 14 00 00 00 mov %gs:0x14,%eax 804844a: 89 44 24 3c mov %eax,0x3c(%esp) 804844e: 31 c0 xor %eax,%eax 8048450: c6 44 24 35 61 movb $0x61,0x35(%esp) 8048455: c7 44 24 28 0a 00 00 movl $0xa,0x28(%esp) 804845c: 00 804845d: b8 a4 70 9d 3f mov $0x3f9d70a4,%eax 8048462: 89 44 24 2c mov %eax,0x2c(%esp) 8048466: dd 05 90 87 04 08 fldl 0x8048790 804846c: dd 5c 24 20 fstpl 0x20(%esp) 8048470: c7 44 24 30 f0 86 04 movl $0x80486f0,0x30(%esp) 8048477: 08 8048478: c7 44 24 36 68 65 6c movl $0x6c6c6568,0x36(%esp) 804847f: 6c 8048480: 66 c7 44 24 3a 6f 00 movw $0x6f,0x3a(%esp) 8048487: b8 f6 86 04 08 mov $0x80486f6,%eax 804848c: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 8048493: 00 8048494: 89 04 24 mov %eax,(%esp) 8048497: e8 a4 fe ff ff call 8048340 804849c: b8 fe 86 04 08 mov $0x80486fe,%eax 80484a1: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 80484a8: 00 80484a9: 89 04 24 mov %eax,(%esp) 80484ac: e8 8f fe ff ff call 8048340 80484b1: b8 09 87 04 08 mov $0x8048709,%eax 80484b6: c7 44 24 04 08 00 00 movl $0x8,0x4(%esp) 80484bd: 00 80484be: 89 04 24 mov %eax,(%esp) 80484c1: e8 7a fe ff ff call 8048340 80484c6: b8 15 87 04 08 mov $0x8048715,%eax 80484cb: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) 80484d2: 00 80484d3: 89 04 24 mov %eax,(%esp) 80484d6: e8 65 fe ff ff call 8048340 80484db: b8 1c 87 04 08 mov $0x804871c,%eax 80484e0: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 80484e7: 00 80484e8: 89 04 24 mov %eax,(%esp) 80484eb: e8 50 fe ff ff call 8048340 80484f0: b8 25 87 04 08 mov $0x8048725,%eax 80484f5: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 80484fc: 00 80484fd: 89 04 24 mov %eax,(%esp) 8048500: e8 3b fe ff ff call 8048340 8048505: b8 2d 87 04 08 mov $0x804872d,%eax 804850a: c7 44 24 04 08 00 00 movl $0x8,0x4(%esp) 8048511: 00 8048512: 89 04 24 mov %eax,(%esp) 8048515: e8 26 fe ff ff call 8048340 804851a: b8 36 87 04 08 mov $0x8048736,%eax 804851f: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) 8048526: 00 8048527: 89 04 24 mov %eax,(%esp) 804852a: e8 11 fe ff ff call 8048340 804852f: b8 40 87 04 08 mov $0x8048740,%eax 8048534: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 804853b: 00 804853c: 89 04 24 mov %eax,(%esp) 804853f: e8 fc fd ff ff call 8048340 8048544: b8 49 87 04 08 mov $0x8048749,%eax 8048549: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 8048550: 00 8048551: 89 04 24 mov %eax,(%esp) 8048554: e8 e7 fd ff ff call 8048340 8048559: b8 54 87 04 08 mov $0x8048754,%eax 804855e: c7 44 24 04 08 00 00 movl $0x8,0x4(%esp) 8048565: 00 8048566: 89 04 24 mov %eax,(%esp) 8048569: e8 d2 fd ff ff call 8048340 804856e: b8 61 87 04 08 mov $0x8048761,%eax 8048573: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) 804857a: 00 804857b: 89 04 24 mov %eax,(%esp) 804857e: e8 bd fd ff ff call 8048340 8048583: b8 1c 87 04 08 mov $0x804871c,%eax 8048588: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 804858f: 00 8048590: 89 04 24 mov %eax,(%esp) 8048593: e8 a8 fd ff ff call 8048340 8048598: b8 25 87 04 08 mov $0x8048725,%eax 804859d: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 80485a4: 00 80485a5: 89 04 24 mov %eax,(%esp) 80485a8: e8 93 fd ff ff call 8048340 80485ad: b8 2d 87 04 08 mov $0x804872d,%eax 80485b2: c7 44 24 04 08 00 00 movl $0x8,0x4(%esp) 80485b9: 00 80485ba: 89 04 24 mov %eax,(%esp) 80485bd: e8 7e fd ff ff call 8048340 80485c2: b8 69 87 04 08 mov $0x8048769,%eax 80485c7: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 80485ce: 00 80485cf: 89 04 24 mov %eax,(%esp) 80485d2: e8 69 fd ff ff call 8048340 80485d7: b8 73 87 04 08 mov $0x8048773,%eax 80485dc: c7 44 24 04 06 00 00 movl $0x6,0x4(%esp) 80485e3: 00 80485e4: 89 04 24 mov %eax,(%esp) 80485e7: e8 54 fd ff ff call 8048340 80485ec: b8 7f 87 04 08 mov $0x804877f,%eax 80485f1: c7 44 24 04 06 00 00 movl $0x6,0x4(%esp) 80485f8: 00 80485f9: 89 04 24 mov %eax,(%esp) 80485fc: e8 3f fd ff ff call 8048340 8048601: b8 00 00 00 00 mov $0x0,%eax 8048606: 8b 54 24 3c mov 0x3c(%esp),%edx 804860a: 65 33 15 14 00 00 00 xor %gs:0x14,%edx 8048611: 74 05 je 8048618 8048613: e8 38 fd ff ff call 8048350 <__stack_chk_fail@plt> 8048618: c9 leave 8048619: c3 ret 804861a: 90 nop 804861b: 90 nop 804861c: 90 nop 804861d: 90 nop 804861e: 90 nop 804861f: 90 nop 08048620 <__libc_csu_init>: 8048620: 55 push %ebp 8048621: 57 push %edi 8048622: 56 push %esi 8048623: 53 push %ebx 8048624: e8 69 00 00 00 call 8048692 <__i686.get_pc_thunk.bx> 8048629: 81 c3 cb 19 00 00 add $0x19cb,%ebx 804862f: 83 ec 1c sub $0x1c,%esp 8048632: 8b 6c 24 30 mov 0x30(%esp),%ebp 8048636: 8d bb 20 ff ff ff lea -0xe0(%ebx),%edi 804863c: e8 b7 fc ff ff call 80482f8 <_init> 8048641: 8d 83 20 ff ff ff lea -0xe0(%ebx),%eax 8048647: 29 c7 sub %eax,%edi 8048649: c1 ff 02 sar $0x2,%edi 804864c: 85 ff test %edi,%edi 804864e: 74 29 je 8048679 <__libc_csu_init+0x59> 8048650: 31 f6 xor %esi,%esi 8048652: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 8048658: 8b 44 24 38 mov 0x38(%esp),%eax 804865c: 89 2c 24 mov %ebp,(%esp) 804865f: 89 44 24 08 mov %eax,0x8(%esp) 8048663: 8b 44 24 34 mov 0x34(%esp),%eax 8048667: 89 44 24 04 mov %eax,0x4(%esp) 804866b: ff 94 b3 20 ff ff ff call *-0xe0(%ebx,%esi,4) 8048672: 83 c6 01 add $0x1,%esi 8048675: 39 fe cmp %edi,%esi 8048677: 75 df jne 8048658 <__libc_csu_init+0x38> 8048679: 83 c4 1c add $0x1c,%esp 804867c: 5b pop %ebx 804867d: 5e pop %esi 804867e: 5f pop %edi 804867f: 5d pop %ebp 8048680: c3 ret 8048681: eb 0d jmp 8048690 <__libc_csu_fini> 8048683: 90 nop 8048684: 90 nop 8048685: 90 nop 8048686: 90 nop 8048687: 90 nop 8048688: 90 nop 8048689: 90 nop 804868a: 90 nop 804868b: 90 nop 804868c: 90 nop 804868d: 90 nop 804868e: 90 nop 804868f: 90 nop 08048690 <__libc_csu_fini>: 8048690: f3 c3 repz ret 08048692 <__i686.get_pc_thunk.bx>: 8048692: 8b 1c 24 mov (%esp),%ebx 8048695: c3 ret 8048696: 90 nop 8048697: 90 nop 8048698: 90 nop 8048699: 90 nop 804869a: 90 nop 804869b: 90 nop 804869c: 90 nop 804869d: 90 nop 804869e: 90 nop 804869f: 90 nop 080486a0 <__do_global_ctors_aux>: 80486a0: 55 push %ebp 80486a1: 89 e5 mov %esp,%ebp 80486a3: 53 push %ebx 80486a4: 83 ec 04 sub $0x4,%esp 80486a7: a1 14 9f 04 08 mov 0x8049f14,%eax 80486ac: 83 f8 ff cmp $0xffffffff,%eax 80486af: 74 13 je 80486c4 <__do_global_ctors_aux+0x24> 80486b1: bb 14 9f 04 08 mov $0x8049f14,%ebx 80486b6: 66 90 xchg %ax,%ax 80486b8: 83 eb 04 sub $0x4,%ebx 80486bb: ff d0 call *%eax 80486bd: 8b 03 mov (%ebx),%eax 80486bf: 83 f8 ff cmp $0xffffffff,%eax 80486c2: 75 f4 jne 80486b8 <__do_global_ctors_aux+0x18> 80486c4: 83 c4 04 add $0x4,%esp 80486c7: 5b pop %ebx 80486c8: 5d pop %ebp 80486c9: c3 ret 80486ca: 90 nop 80486cb: 90 nop Disassembly of section .fini: 080486cc <_fini>: 80486cc: 53 push %ebx 80486cd: 83 ec 08 sub $0x8,%esp 80486d0: e8 00 00 00 00 call 80486d5 <_fini+0x9> 80486d5: 5b pop %ebx 80486d6: 81 c3 1f 19 00 00 add $0x191f,%ebx 80486dc: e8 cf fc ff ff call 80483b0 <__do_global_dtors_aux> 80486e1: 83 c4 08 add $0x8,%esp 80486e4: 5b pop %ebx 80486e5: c3 ret $0x4,0x4(%esp) 8048493: 00 8048494: 89 04 24 mov %eax,(%esp) 8048497: e8 a4 fe ff ff call 8048340 804849c: b8 fe 86 04 08 mov $0x80486fe,%eax 80484a1: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 80484a8: 00 80484a9: 89 04 24 mov %eax,(%esp) 80484ac: e8 8f fe ff ff call 8048340 80484b1: b8 09 87 04 08 mov $0x8048709,%eax 80484b6: c7 44 24 04 08 00 00 movl $0x8,0x4(%esp) 80484bd: 00 80484be: 89 04 24 mov %eax,(%esp) 80484c1: e8 7a fe ff ff call 8048340 80484c6: b8 15 87 04 08 mov $0x8048715,%eax 80484cb: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) 80484d2: 00 80484d3: 89 04 24 mov %eax,(%esp) 80484d6: e8 65 fe ff ff call 8048340 80484db: b8 1c 87 04 08 mov $0x804871c,%eax 80484e0: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 80484e7: 00 80484e8: 89 04 24 mov %eax,(%esp) 80484eb: e8 50 fe ff ff call 8048340 80484f0: b8 25 87 04 08 mov $0x8048725,%eax 80484f5: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 80484fc: 00 80484fd: 89 04 24 mov %eax,(%esp) 8048500: e8 3b fe ff ff call 8048340 8048505: b8 2d 87 04 08 mov $0x804872d,%eax 804850a: c7 44 24 04 08 00 00 movl $0x8,0x4(%esp) 8048511: 00 8048512: 89 04 24 mov %eax,(%esp) 8048515: e8 26 fe ff ff call 8048340 804851a: b8 36 87 04 08 mov $0x8048736,%eax 804851f: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) 8048526: 00 8048527: 89 04 24 mov %eax,(%esp) 804852a: e8 11 fe ff ff call 8048340 804852f: b8 40 87 04 08 mov $0x8048740,%eax 8048534: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 804853b: 00 804853c: 89 04 24 mov %eax,(%esp) 804853f: e8 fc fd ff ff call 8048340 8048544: b8 49 87 04 08 mov $0x8048749,%eax 8048549: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 8048550: 00 8048551: 89 04 24 mov %eax,(%esp) 8048554: e8 e7 fd ff ff call 8048340 8048559: b8 54 87 04 08 mov $0x8048754,%eax 804855e: c7 44 24 04 08 00 00 movl $0x8,0x4(%esp) 8048565: 00 8048566: 89 04 24 mov %eax,(%esp) 8048569: e8 d2 fd ff ff call 8048340 804856e: b8 61 87 04 08 mov $0x8048761,%eax 8048573: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) 804857a: 00 804857b: 89 04 24 mov %eax,(%esp) 804857e: e8 bd fd ff ff call 8048340 8048583: b8 1c 87 04 08 mov $0x804871c,%eax 8048588: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 804858f: 00 8048590: 89 04 24 mov %eax,(%esp) 8048593: e8 a8 fd ff ff call 8048340 8048598: b8 25 87 04 08 mov $0x8048725,%eax 804859d: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 80485a4: 00 80485a5: 89 04 24 mov %eax,(%esp) 80485a8: e8 93 fd ff ff call 8048340 80485ad: b8 2d 87 04 08 mov $0x804872d,%eax 80485b2: c7 44 24 04 08 00 00 movl $0x8,0x4(%esp) 80485b9: 00 80485ba: 89 04 24 mov %eax,(%esp) 80485bd: e8 7e fd ff ff call 8048340 80485c2: b8 69 87 04 08 mov $0x8048769,%eax 80485c7: c7 44 24 04 04 00 00 movl $0x4,0x4(%esp) 80485ce: 00 80485cf: 89 04 24 mov %eax,(%esp) 80485d2: e8 69 fd ff ff call 8048340 80485d7: b8 73 87 04 08 mov $0x8048773,%eax 80485dc: c7 44 24 04 06 00 00 movl $0x6,0x4(%esp) 80485e3: 00 80485e4: 89 04 24 mov %eax,(%esp) 80485e7: e8 54 fd ff ff call 8048340 80485ec: b8 7f 87 04 08 mov $0x804877f,%eax 80485f1: c7 44 24 04 06 00 00 movl $0x6,0x4(%esp) 80485f8: 00 80485f9: 89 04 24 mov %eax,(%esp) 80485fc: e8 3f fd ff ff call 8048340 8048601: b8 00 00 00 00 mov $0x0,%eax 8048606: 8b 54 24 3c mov 0x3c(%esp),%edx 804860a: 65 33 15 14 00 00 00 xor %gs:0x14,%edx 8048611: 74 05 je 8048618 8048613: e8 38 fd ff ff call 8048350 <__stack_chk_fail@plt> 8048618: c9 leave 8048619: c3 ret 804861a: 90 nop 804861b: 90 nop 804861c: 90 nop 804861d: 90 nop 804861e: 90 nop 804861f: 90 nop 08048620 <__libc_csu_init>: 8048620: 55 push %ebp 8048621: 57 push %edi 8048622: 56 push %esi 8048623: 53 push %ebx 8048624: e8 69 00 00 00 call 8048692 <__i686.get_pc_thunk.bx> 8048629: 81 c3 cb 19 00 00 add $0x19cb,%ebx 804862f: 83 ec 1c sub $0x1c,%esp 8048632: 8b 6c 24 30 mov 0x30(%esp),%ebp 8048636: 8d bb 20 ff ff ff lea -0xe0(%ebx),%edi 804863c: e8 b7 fc ff ff call 80482f8 <_init> 8048641: 8d 83 20 ff ff ff lea -0xe0(%ebx),%eax 8048647: 29 c7 sub %eax,%edi 8048649: c1 ff 02 sar $0x2,%edi 804864c: 85 ff test %edi,%edi 804864e: 74 29 je 8048679 <__libc_csu_init+0x59> 8048650: 31 f6 xor %esi,%esi 8048652: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 8048658: 8b 44 24 38 mov 0x38(%esp),%eax 804865c: 89 2c 24 mov %ebp,(%esp) 804865f: 89 44 24 08 mov %eax,0x8(%esp) 8048663: 8b 44 24 34 mov 0x34(%esp),%eax 8048667: 89 44 24 04 mov %eax,0x4(%esp) 804866b: ff 94 b3 20 ff ff ff call *-0xe0(%ebx,%esi,4) 8048672: 83 c6 01 add $0x1,%esi 8048675: 39 fe cmp %edi,%esi 8048677: 75 df jne 8048658 <__libc_csu_init+0x38> 8048679: 83 c4 1c add $0x1c,%esp 804867c: 5b pop %ebx 804867d: 5e pop %esi 804867e: 5f pop %edi 804867f: 5d pop %ebp 8048680: c3 ret 8048681: eb 0d jmp 8048690 <__libc_csu_fini> 8048683: 90 nop 8048684: 90 nop 8048685: 90 nop 8048686: 90 nop 8048687: 90 nop 8048688: 90 nop 8048689: 90 nop 804868a: 90 nop 804868b: 90 nop 804868c: 90 nop 804868d: 90 nop 804868e: 90 nop 804868f: 90 nop 08048690 <__libc_csu_fini>: 8048690: f3 c3 repz ret 08048692 <__i686.get_pc_thunk.bx>: 8048692: 8b 1c 24 mov (%esp),%ebx 8048695: c3 ret 8048696: 90 nop 8048697: 90 nop 8048698: 90 nop 8048699: 90 nop 804869a: 90 nop 804869b: 90 nop 804869c: 90 nop 804869d: 90 nop 804869e: 90 nop 804869f: 90 nop 080486a0 <__do_global_ctors_aux>: 80486a0: 55 push %ebp 80486a1: 89 e5 mov %esp,%ebp 80486a3: 53 push %ebx 80486a4: 83 ec 04 sub $0x4,%esp 80486a7: a1 14 9f 04 08 mov 0x8049f14,%eax 80486ac: 83 f8 ff cmp $0xffffffff,%eax 80486af: 74 13 je 80486c4 <__do_global_ctors_aux+0x24> 80486b1: bb 14 9f 04 08 mov $0x8049f14,%ebx 80486b6: 66 90 xchg %ax,%ax 80486b8: 83 eb 04 sub $0x4,%ebx 80486bb: ff d0 call *%eax 80486bd: 8b 03 mov (%ebx),%eax 80486bf: 83 f8 ff cmp $0xffffffff,%eax 80486c2: 75 f4 jne 80486b8 <__do_global_ctors_aux+0x18> 80486c4: 83 c4 04 add $0x4,%esp 80486c7: 5b pop %ebx 80486c8: 5d pop %ebp 80486c9: c3 ret 80486ca: 90 nop 80486cb: 90 nop Disassembly of section .fini: 080486cc <_fini>: 80486cc: 53 push %ebx 80486cd: 83 ec 08 sub $0x8,%esp 80486d0: e8 00 00 00 00 call 80486d5 <_fini+0x9> 80486d5: 5b pop %ebx 80486d6: 81 c3 1f 19 00 00 add $0x191f,%ebx 80486dc: e8 cf fc ff ff call 80483b0 <__do_global_dtors_aux> 80486e1: 83 c4 08 add $0x8,%esp 80486e4: 5b pop %ebx 80486e5: c3 ret

 

 

 

 

补充:编译命令:gcc sizeof.c -o sizeof -Wall。(-Wall是为了将警告信息也显示出来)一下是分步骤

C语言编译过程
预处理:gcc sizeof.c -o sizeof.i -E
处理预处理语句(比如#include ,#define,#if之类的语句),去掉注释
编译:gcc sizeof.i -o sizeof.s -S
将C语言语句转化为汇编
汇编:gcc sizeof.s -o sizeof.o -c
将汇编语句转化为二进制代码(只检查当前文件有没有语法问题)
链接:gcc sizeof.o -o sizeof

跟所有的程序文件联合生成(建立数据段)可执行程序(比如链接多个文件,或者是调用其他库文件等)

    注:生成的可执行文件,如果没有可执行权限的需要添加可执行权限。

执行命令 chmod a+x sizeof           (将全部人员都添加可执行权限,all(包括拥有者,同组,其他用户))

你可能感兴趣的:(Linux)