Problem 1 --------- goose: pushl %ebp movl %esp, %ebp movl $-4, %eax popl %ebp ret .size goose, .-goose cow: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax subl 12(%ebp), %eax popl %ebp ret .size cow, .-cow .globl pig .type pig, @function pig: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax leal (%eax,%eax,2), %eax popl %ebp ret .size pig, .-pig .globl sheep .type sheep, @function sheep: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax shrl $31, %eax popl %ebp ret .size sheep, .-sheep .globl duck .type duck, @function duck: pushl %ebp movl %esp, %ebp pushl %ebx movl 8(%ebp), %ebx pushl %ebx call sheep movl %ebx, %edx testl %eax, %eax je .L6 negl %edx .L6: movl %edx, %eax addl $4, %esp popl %ebx popl %ebp ret .size duck, .-duck .globl goose .type goose, @function Problem 2 --------- a b: which flags are set (1), rest are clear (0) -4 0xfffffffc: ZF 4 0xfffffffc: SF -1 1: CF 2 0x8000000: OF 0x7fffffff 0x80000000: OF 0x8000000 0x7fffffff: SF CF OF 1 0x7ffffffff: none 0x80000000 0x80000000: ZF 0x7fffffff 0xffffffff: SF Multi-word arithematic, ie, implementing long longs Problem 3 --------- fun2 Problem 4 --------- Fragment 3 Problem 5 --------- int dog(int x, int y) { int i, result; result = 1; for(i=x;i< y;i+=2) result = result*i; return result; } Problem 6 --------- int cat(int x, int y) { int i, ret; ret = 0; i = x; while(i--) { ret = ret+i*y; } return ret; } Problem 7 --------- int frog(int a, int b) { int result; switch(a) { case 1: case 5: result = 7; break; case 3: result = b-1; break; case 6: b++; case 7: result = b; break; default: result = -1; } return result; } Problem 8 --------- ret address 0x04 saved ebp 0x00 len 0x08 buf 0xf8 esp 0xf0 pointer to ``\%s'' 0xf0 0x696e6f74 (gdb) x 0xbffff990 0xbffff990: 0x00000008 (gdb) x 0xbffff98c 0xbffff98c: 0x08048584 (gdb) x 0xbffff988 0xbffff988: 0xbffff900 {\em buffer overwrite from null character!} (gdb) x 0xbffff984 0xbffff984: 0x736e656b (gdb) x 0xbffff980 0xbffff980: 0x63696863 (gdb) x 0xbffff97c 0xbffff97c: 0xbffff980 (gdb) x 0xbffff978 0xbffff978: 0x08048640 Problem 9 --------- bear: pushl %ebp movl %esp, %ebp pushl %esi pushl %ebx movl 8(%ebp), %edx movl 12(%ebp), %ebx movl 16(%ebp), %esi cmpl %ebx, %edx jge .L7 movl global, %ecx .L5: movl %esi, %eax imull %edx, %eax leal (%ecx,%eax), %ecx incl %edx cmpl %ebx, %edx jl .L5 movl %ecx, global .L7: movl global, %eax popl %ebx popl %esi popl %ebp ret Problem 10 ---------- 0xbffff9a4 0x3 n 0xbffff9a0 0x21 val 0xbffff99c 0x80483db return address 0xbffff998 0xbffff9a8 saved ebp 0xbffff994 n/a saved ebx 0xbffff990 0x2 n-1 0xbffff98c 0x21 val 0xbffff988 0x80483b3 return address 0xbffff984 0xbffff998 saved ebp 0xbffff980 0x21 saved ebx (haven't done this yet..) 0xbffff97c the lea instruction (0x80483b3