Skip to content

Instantly share code, notes, and snippets.

@ccckmit
Created March 20, 2015 01:32
Show Gist options
  • Save ccckmit/23372fb9883ed13d466c to your computer and use it in GitHub Desktop.
Save ccckmit/23372fb9883ed13d466c to your computer and use it in GitHub Desktop.
// file df.c
#include <stdio.h>
#include <math.h>
double dx = 0.0001;
double df(double x, double (*f)(double)) {
double dy = (*f)(x+dx)-(*f)(x);
return dy/dx;
}
int main() {
printf("df(0.5, sin)=%6.2f\n", df(0.5, sin));
}
/*
D:\ccc\c>gcc -c df.c -o df.o
D:\ccc\c>objdump -d df.o
df.o: file format pe-i386
Disassembly of section .text:
00000000 <_df>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 18 sub $0x18,%esp
6: dd 45 08 fldl 0x8(%ebp)
9: dc 05 00 00 00 00 faddl 0x0
f: dd 1c 24 fstpl (%esp)
12: 8b 45 10 mov 0x10(%ebp),%eax
15: ff d0 call *%eax
17: dd 5d f0 fstpl 0xfffffff0(%ebp)
1a: dd 45 08 fldl 0x8(%ebp)
1d: dd 1c 24 fstpl (%esp)
20: 8b 45 10 mov 0x10(%ebp),%eax
23: ff d0 call *%eax
25: dc 6d f0 fsubrl 0xfffffff0(%ebp)
28: dd 5d f8 fstpl 0xfffffff8(%ebp)
2b: dd 45 f8 fldl 0xfffffff8(%ebp)
2e: dc 35 00 00 00 00 fdivl 0x0
34: c9 leave
35: c3 ret
00000036 <_main>:
36: 55 push %ebp
37: 89 e5 mov %esp,%ebp
39: 83 ec 18 sub $0x18,%esp
3c: 83 e4 f0 and $0xfffffff0,%esp
3f: b8 00 00 00 00 mov $0x0,%eax
44: 83 c0 0f add $0xf,%eax
47: 83 c0 0f add $0xf,%eax
4a: c1 e8 04 shr $0x4,%eax
4d: c1 e0 04 shl $0x4,%eax
50: 89 45 fc mov %eax,0xfffffffc(%ebp)
53: 8b 45 fc mov 0xfffffffc(%ebp),%eax
56: e8 00 00 00 00 call 5b <_main+0x25>
5b: e8 00 00 00 00 call 60 <_main+0x2a>
60: c7 44 24 08 00 00 00 movl $0x0,0x8(%esp)
67: 00
68: dd 05 18 00 00 00 fldl 0x18
6e: dd 1c 24 fstpl (%esp)
71: e8 8a ff ff ff call 0 <_df>
76: dd 5c 24 04 fstpl 0x4(%esp)
7a: c7 04 24 00 00 00 00 movl $0x0,(%esp)
81: e8 00 00 00 00 call 86 <_main+0x50>
86: c9 leave
87: c3 ret
88: 90 nop
89: 90 nop
8a: 90 nop
8b: 90 nop
8c: 90 nop
8d: 90 nop
8e: 90 nop
8f: 90 nop
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment