computer system 1

在这里插入图片描述

//ex1 1
#include "stdio.h"
void main(){
    int a=32767,b=100,c=-100;
    printf("a=%d,  b=%d,  c=%d\n",a,b,c);
    printf("a=%0xH,b=%0xH,c=%0xH\n",a,b,c);
}

student1@506-52:~$ vi ex1.c
student1@506-52:~$ gcc -S ex1.c
student1@506-52:~$ cat ex1.s
	.file	"ex1.c"
	.section	.rodata
.LC0:
	.string	"a=%d,  b=%d,  c=%d\n"
.LC1:
	.string	"a=%0xH,b=%0xH,c=%0xH\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	leal	4(%esp), %ecx
	.cfi_def_cfa 1, 0
	andl	$-16, %esp
	pushl	-4(%ecx)
	pushl	%ebp
	.cfi_escape 0x10,0x5,0x2,0x75,0
	movl	%esp, %ebp
	pushl	%ecx
	.cfi_escape 0xf,0x3,0x75,0x7c,0x6
	subl	$20, %esp
	movl	$32767, -20(%ebp)
	movl	$100, -16(%ebp)
	movl	$-100, -12(%ebp)
	pushl	-12(%ebp)
	pushl	-16(%ebp)
	pushl	-20(%ebp)
	pushl	$.LC0
	call	printf
	addl	$16, %esp
	pushl	-12(%ebp)
	pushl	-16(%ebp)
	pushl	-20(%ebp)
	pushl	$.LC1
	call	printf
	addl	$16, %esp
	nop
	movl	-4(%ebp), %ecx
	.cfi_def_cfa 1, 0
	leave
	.cfi_restore 5
	leal	-4(%ecx), %esp
	.cfi_def_cfa 4, 4
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609"
	.section	.note.GNU-stack,"",@progbits

//ex1 1
 804841c:	c7 45 ec ff 7f 00 00 	movl   $0x7fff,-0x14(%ebp)
 8048423:	c7 45 f0 64 00 00 00 	movl   $0x64,-0x10(%ebp)
 804842a:	c7 45 f4 9c ff ff ff 	movl   $0xffffff9c,-0xc(%ebp)
//ex2 1
#include "stdio.h"
void main(){
//  char a=100;
//  short b=100;
//  int c=100;
//  int d=0x12345678;//,e;
    int d=0x22334455;
//  e=d;
//  printf("a=%0xH,b=%0xH,c=%0xH,d=%0xH,e=%0xH\n",a,b,c,d,e);
}
//ex2 1
 804841c:	c6 45 e9 64          	movb   $0x64,-0x17(%ebp)
 8048420:	66 c7 45 ea 64 00    	movw   $0x64,-0x16(%ebp)
 8048426:	c7 45 ec 64 00 00 00 	movl   $0x64,-0x14(%ebp)
 804842d:	c7 45 f0 78 56 34 12 	movl   $0x12345678,-0x10(%ebp)
//ex2 1
student1@506-52:~$ ./ex2
a=64H,b=64H,c=64H,d=12345678H,e=12345678H
student1@506-52:~$ vi ex2.c
student1@506-52:~$ gcc -c ex2.c
student1@506-52:~$ gcc -o ex2 ex2.c
student1@506-52:~$ gcc -S ex2.c
student1@506-52:~$ vim ex2.s
student1@506-52:~$ objdump -d ex2
//ex2 2
#include "stdio.h"
void main(){
    struct record{
        char a;
        int b;
        short c;
        char d;
    };
    struct record R[2];
    R[0].a=1;
    R[0].b=2;
    R[0].c=3;
    R[0].d=4;
    R[1].a=1;
    R[1].b=2;
    R[1].c=3;
    R[1].d=4;

    printf("save data duiqi");

}
//ex2 2
    movb	$1, -36(%ebp)
	movl	$2, -32(%ebp)
	movw	$3, -28(%ebp)
	movb	$4, -26(%ebp)
	movb	$1, -24(%ebp)
	movl	$2, -20(%ebp)
	movw	$3, -16(%ebp)
	movb	$4, -14(%ebp)
//ex3 1
#include "stdio.h"
void main(){
    short si=-32768;
    unsigned short usi=si;
    int i=usi;
    unsigned ui=usi;
    int i1=si;
    unsigned ui1=si;

    int i2=98304;
    short si2=i2;
    unsigned shoet usi2=i2;
    int i3=si2;

    int i4=4294967296;

    printf("si=%d,usi=%u,i=%d,ui=%u,i1=%d,ui1=%u\n",si,usi,i,ui,i1,ui1);
    printf("i2=%d,si2=%d,usi2=%u,i3=%d,i4=%d\n",i2,si2,usi2,i3,i4);
}
//ex3 2
#include "stdio.h"
void main(){
    int i=100,i1=0x7fffffff,i2;
    float f,f1=0x987654321,f2,f3;

    f=i;
    printf("i=%d,f=%f\n",i,f);
    i2=(int)(float)i1;
    f2=(float)(int)f1;
    printf("i1=%d,i2=5d,f1=%f,f2=%f\n");

}

//ex3 3
#include "stdio.h"

int f1(unsigned int n){
    int sum=1,power=1;
    int i;
    for(i=0;i<=n-1;i++){
        printf("i=%d\n",i);
        power*=2;
        sum+=power;
    }
    return sum;

}

void main(){
    int x=0;
    x=f1(0);
    return 0;
}

//ex4
#include "stdio.h"
main(){
    int a=305419896,b=1985229328,c,d;
    unsigned int ua=305419896,ub=1985229328,uc,ud;

    c=a+b;
    uc=ua+ub;
    d=a-b;
    ud=ua-ub;

    printf("%d+%d=%d\n",a,b,c);
    printf("%u+%u=%u\n",ua,ub,uc);
    printf("%d-%d=%d\n",a,b,d);
    printf("%u-%u=%u\n",ua,ub,ud);

}

//ex4
0804840b <main>:
 804840b:	8d 4c 24 04          	lea    0x4(%esp),%ecx
 804840f:	83 e4 f0             	and    $0xfffffff0,%esp
 8048412:	ff 71 fc             	pushl  -0x4(%ecx)
 8048415:	55                   	push   %ebp
 8048416:	89 e5                	mov    %esp,%ebp
 8048418:	51                   	push   %ecx
 8048419:	83 ec 24             	sub    $0x24,%esp
 804841c:	c7 45 d8 78 56 34 12 	movl   $0x12345678,-0x28(%ebp)
 8048423:	c7 45 dc 10 32 54 76 	movl   $0x76543210,-0x24(%ebp)
 804842a:	c7 45 e0 78 56 34 12 	movl   $0x12345678,-0x20(%ebp)
 8048431:	c7 45 e4 10 32 54 76 	movl   $0x76543210,-0x1c(%ebp)
 8048438:	8b 55 d8             	mov    -0x28(%ebp),%edx
 804843b:	8b 45 dc             	mov    -0x24(%ebp),%eax
 804843e:	01 d0                	add    %edx,%eax
 8048440:	89 45 e8             	mov    %eax,-0x18(%ebp)
 8048443:	8b 55 e0             	mov    -0x20(%ebp),%edx
 8048446:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 8048449:	01 d0                	add    %edx,%eax
 804844b:	89 45 ec             	mov    %eax,-0x14(%ebp)
 804844e:	8b 45 d8             	mov    -0x28(%ebp),%eax
 8048451:	2b 45 dc             	sub    -0x24(%ebp),%eax
 8048454:	89 45 f0             	mov    %eax,-0x10(%ebp)
 8048457:	8b 45 e0             	mov    -0x20(%ebp),%eax
 804845a:	2b 45 e4             	sub    -0x1c(%ebp),%eax
 804845d:	89 45 f4             	mov    %eax,-0xc(%ebp)
 8048460:	ff 75 e8             	pushl  -0x18(%ebp)
 8048463:	ff 75 dc             	pushl  -0x24(%ebp)
 8048466:	ff 75 d8             	pushl  -0x28(%ebp)
 8048469:	68 50 85 04 08       	push   $0x8048550
 804846e:	e8 6d fe ff ff       	call   80482e0 <printf@plt>
 8048473:	83 c4 10             	add    $0x10,%esp
 8048476:	ff 75 ec             	pushl  -0x14(%ebp)
 8048479:	ff 75 e4             	pushl  -0x1c(%ebp)
 804847c:	ff 75 e0             	pushl  -0x20(%ebp)
 804847f:	68 5a 85 04 08       	push   $0x804855a
 8048484:	e8 57 fe ff ff       	call   80482e0 <printf@plt>
 8048489:	83 c4 10             	add    $0x10,%esp
 804848c:	ff 75 f0             	pushl  -0x10(%ebp)
 804848f:	ff 75 dc             	pushl  -0x24(%ebp)
 8048492:	ff 75 d8             	pushl  -0x28(%ebp)
 8048495:	68 64 85 04 08       	push   $0x8048564
 804849a:	e8 41 fe ff ff       	call   80482e0 <printf@plt>
 804849f:	83 c4 10             	add    $0x10,%esp
 80484a2:	ff 75 f4             	pushl  -0xc(%ebp)
 80484a5:	ff 75 e4             	pushl  -0x1c(%ebp)
 80484a8:	ff 75 e0             	pushl  -0x20(%ebp)
 80484ab:	68 6e 85 04 08       	push   $0x804856e
 80484b0:	e8 2b fe ff ff       	call   80482e0 <printf@plt>
 80484b5:	83 c4 10             	add    $0x10,%esp
 80484b8:	b8 00 00 00 00       	mov    $0x0,%eax
 80484bd:	8b 4d fc             	mov    -0x4(%ebp),%ecx
 80484c0:	c9                   	leave  
 80484c1:	8d 61 fc             	lea    -0x4(%ecx),%esp
 80484c4:	c3                   	ret    
 80484c5:	66 90                	xchg   %ax,%ax
 80484c7:	66 90                	xchg   %ax,%ax
 80484c9:	66 90                	xchg   %ax,%ax
 80484cb:	66 90                	xchg   %ax,%ax
 80484cd:	66 90                	xchg   %ax,%ax
 80484cf:	90                   	nop
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值