#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
804841 c: c7 45 ec ff 7f 00 00 movl $0x7fff , - 0x14 ( % ebp)
8048423 : c7 45 f0 64 00 00 00 movl $0x64 , - 0x10 ( % ebp)
804842 a: c7 45 f4 9 c ff ff ff movl $0xffffff9c , - 0xc ( % ebp)
#include "stdio.h"
void main ( ) {
int d= 0x22334455 ;
}
804841 c: 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)
804842 d: c7 45 f0 78 56 34 12 movl $0x12345678 , - 0x10 ( % ebp)
student1@506 - 52 : ~ $ . / ex2
a= 64 H, b= 64 H, c= 64 H, d= 12345678 H, e= 12345678 H
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
#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" ) ;
}
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)
#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) ;
}
#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" ) ;
}
#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 ;
}
#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) ;
}
0804840 b < main> :
804840 b: 8 d 4 c 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
804841 c: c7 45 d8 78 56 34 12 movl $0x12345678 , - 0x28 ( % ebp)
8048423 : c7 45 dc 10 32 54 76 movl $0x76543210 , - 0x24 ( % ebp)
804842 a: c7 45 e0 78 56 34 12 movl $0x12345678 , - 0x20 ( % ebp)
8048431 : c7 45 e4 10 32 54 76 movl $0x76543210 , - 0x1c ( % ebp)
8048438 : 8 b 55 d8 mov - 0x28 ( % ebp) , % edx
804843 b: 8 b 45 dc mov - 0x24 ( % ebp) , % eax
804843 e: 01 d0 add % edx, % eax
8048440 : 89 45 e8 mov % eax, - 0x18 ( % ebp)
8048443 : 8 b 55 e0 mov - 0x20 ( % ebp) , % edx
8048446 : 8 b 45 e4 mov - 0x1c ( % ebp) , % eax
8048449 : 01 d0 add % edx, % eax
804844 b: 89 45 ec mov % eax, - 0x14 ( % ebp)
804844 e: 8 b 45 d8 mov - 0x28 ( % ebp) , % eax
8048451 : 2 b 45 dc sub - 0x24 ( % ebp) , % eax
8048454 : 89 45 f0 mov % eax, - 0x10 ( % ebp)
8048457 : 8 b 45 e0 mov - 0x20 ( % ebp) , % eax
804845 a: 2 b 45 e4 sub - 0x1c ( % ebp) , % eax
804845 d: 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
804846 e: e8 6 d 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)
804847 c: ff 75 e0 pushl - 0x20 ( % ebp)
804847f : 68 5 a 85 04 08 push $0x804855a
8048484 : e8 57 fe ff ff call 80482e0 < printf@plt>
8048489 : 83 c4 10 add $0x10 , % esp
804848 c: 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
804849 a: e8 41 fe ff ff call 80482e0 < printf@plt>
804849f : 83 c4 10 add $0x10 , % esp
80484 a2: ff 75 f4 pushl - 0xc ( % ebp)
80484 a5: ff 75 e4 pushl - 0x1c ( % ebp)
80484 a8: ff 75 e0 pushl - 0x20 ( % ebp)
80484 ab: 68 6 e 85 04 08 push $0x804856e
80484 b0: e8 2 b fe ff ff call 80482e0 < printf@plt>
80484 b5: 83 c4 10 add $0x10 , % esp
80484 b8: b8 00 00 00 00 mov $0x0 , % eax
80484 bd: 8 b 4 d fc mov - 0x4 ( % ebp) , % ecx
80484 c0: c9 leave
80484 c1: 8 d 61 fc lea - 0x4 ( % ecx) , % esp
80484 c4: c3 ret
80484 c5: 66 90 xchg % ax, % ax
80484 c7: 66 90 xchg % ax, % ax
80484 c9: 66 90 xchg % ax, % ax
80484 cb: 66 90 xchg % ax, % ax
80484 cd: 66 90 xchg % ax, % ax
80484 cf: 90 nop