x86_32 Assembly (I am very new to it, it may not be the best way to do it, comments welcome):
#define ENTER_FN \
pushl %ebp; \
movl %esp, %ebp
#define EXIT_FN \
movl %ebp, %esp; \
popl %ebp; \
ret
.global main
calculate_fabcx: #c b a x
ENTER_FN
# %eax= a*x*x
movl 20(%ebp), %eax
imull %eax, %eax
imull 16(%ebp), %eax
# %ebx=b*x
movl 12(%ebp), %ebx
imull 20(%ebp), %ebx
# %eax = f(x)
addl %ebx, %eax
addl 8(%ebp), %eax
EXIT_FN
calculate_f: #x
ENTER_FN
pushl 8(%ebp) # push x
movl $0xFFFFFFFF, %eax # replace by a
pushl %eax
movl $0xEEEEEEEE, %eax # replace by b
pushl %eax
movl $0xDDDDDDDD, %eax # replace by c
pushl %eax
movl $calculate_fabcx, %eax
call *%eax
popl %ecx
popl %ecx
popl %ecx
popl %ecx
EXIT_FN
.set calculate_f_len, . - calculate_f
generate_f: #a b c
ENTER_FN
#allocate memory
pushl $calculate_f_len
call malloc
popl %ecx
pushl $calculate_f_len
pushl $calculate_f
pushl %eax
call copy_bytes
popl %eax
popl %ecx
popl %ecx
movl %eax, %ecx
addl $7, %ecx
movl 8(%ebp), %edx
movl %edx, (%ecx)
addl $6, %ecx
movl 12(%ebp), %edx
movl %edx, (%ecx)
addl $6, %ecx
movl 16(%ebp), %edx
movl %edx, (%ecx)
EXIT_FN
format:
.ascii "%d\n\0"
main:
ENTER_FN
pushl $1601
pushl $-79
pushl $1
call generate_f
popl %ecx
popl %ecx
popl %ecx
pushl $42
call *%eax
popl %ecx
pushl %eax
pushl $format
call printf
popl %ecx
popl %ecx
movl $0, %eax
EXIT_FN
copy_bytes: #dest source length
ENTER_FN
subl $24, %esp
movl 8(%ebp), %ecx # dest
movl %ecx, -4(%ebp)
movl 12(%ebp), %ebx # source
movl %ebx, -8(%ebp)
movl 16(%ebp), %eax # length
movl %eax, -12(%ebp)
addl %eax, %ecx # last dest-byte
movl %ecx, -16(%ebp)
addl %eax, %edx # last source-byte
movl %ecx, -20(%ebp)
movl -4(%ebp), %eax
movl -8(%ebp), %ebx
movl -16(%ebp), %ecx
copy_bytes_2:
movb (%ebx), %dl
movb %dl, (%eax)
incl %eax
incl %ebx
cmp %eax, %ecx
jne copy_bytes_2
EXIT_FN
By coincidence, this thread fits perfectly to whan I am doing at the moment, namely, collecting implementations of Church Numerals in several languages (which is a similar problem, but slightly more complicated). I have already posted some (javascript, java, c++, haskell, etc.) on my Blog, for example here and in older posts, just if somebody is interested in this (or has an additional implementation for me ^^).