Title: Bits and Bytes September 1, 2005
1Bits and BytesSeptember 1, 2005
15-213 The Class That Gives CMU Its Zip!
class02.ppt
15-213 F05
2C Program
include ltstdio.hgt include ltstdlib.hgt char
buf2 "Hello", "Goodbye" int main()
int i random() 1 printf("s World!\n",
bufi) return 0
3Object Code (Window/Cygwin)
00401050 lt_maingt 401050 55
push ebp 401051 b8 10 00 00 00 mov
0x10,eax 401056 89 e5 mov
esp,ebp 401058 83 ec 08 sub
0x8,esp 40105b 83 e4 f0 and
0xfffffff0,esp 40105e e8 2d 00 00 00
call 401090 lt___chkstkgt 401063 e8 b8 00 00
00 call 401120 lt___maingt 401068 e8 d3
00 00 00 call 401140 lt_randomgt
40106d c7 04 24 0e 30 40 00 movl
0x40300e,(esp) 401074 83 e0 01
and 0x1,eax 401077 8b 04 85 00 20 40 00
mov 0x402000(,eax,4),eax 40107e 89 44 24
04 mov eax,0x4(esp) 401082 e8
a9 00 00 00 call 401130 lt_printfgt
401087 c9 leave
401088 31 c0 xor eax,eax
40108a c3 ret
4Object Code (Linux/IA32)
080483b0 ltmaingt 80483b0 55
push ebp 80483b1 89 e5 mov
esp,ebp 80483b3 83 ec 08 sub
0x8,esp 80483b6 83 e4 f0 and
0xfffffff0,esp 80483b9 83 ec 10
sub 0x10,esp 80483bc e8 07 ff ff ff
call 80482c8 ltrandom_at_pltgt 80483c1 83 e0 01
and 0x1,eax 80483c4 c7 04 24 da
84 04 08 movl 0x80484da,(esp) 80483cb 8b
04 85 f0 95 04 08 mov 0x80495f0(,eax,4),eax
80483d2 89 44 24 04 mov
eax,0x4(esp) 80483d6 e8 0d ff ff ff
call 80482e8 ltprintf_at_pltgt 80483db c9
leave 80483dc 31 c0
xor eax,eax 80483de c3
ret
5Object Code (Linux/x86-64)
0000000000400500 ltmaingt 400500 48 83 ec 08
sub 0x8,rsp 400504 e8 17 ff ff ff
callq 400420 ltrandom_at_pltgt 400509 83 e0
01 and 0x1,eax 40050c bf 2a
06 40 00 mov 0x40062a,edi
400511 48 98 cltq
400513 48 8b 34 c5 10 09 50 mov
0x500910(,rax,8),rsi 40051a 00 40051b 31
c0 xor eax,eax 40051d e8
0e ff ff ff callq 400430 ltprintf_at_pltgt
400522 31 c0 xor eax,eax
400524 48 83 c4 08 add 0x8,rsp
400528 c3 retq
6Examining Data Representations
typedef unsigned char pointer void
show_bytes(pointer start, int len) int i
for (i 0 i lt len i) printf(".2x ",
starti) printf("\n") int main(int argc,
char argv) int i for (i 1 i lt argc
i) long int v strtol(argvi, NULL,
0) show_bytes((pointer) v, sizeof(long))
return 0