summaryrefslogtreecommitdiff
path: root/md/writeup/assembler_calculate_polynomial.md
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2021-05-27 21:10:45 +0100
committerFreeArtMan <dos21h@gmail.com>2021-05-27 21:10:45 +0100
commitefa24b220d9633d5d7bfef632b33df180dcb0e74 (patch)
treeac8502acf0116fbbb42a09c6956be70b9a3fc49f /md/writeup/assembler_calculate_polynomial.md
parente63ed8a651e5246f8698a9c1c3e540029710d0e9 (diff)
downloadmd-content-efa24b220d9633d5d7bfef632b33df180dcb0e74.tar.gz
md-content-efa24b220d9633d5d7bfef632b33df180dcb0e74.zip
Update 10 html to md articles
Diffstat (limited to 'md/writeup/assembler_calculate_polynomial.md')
-rw-r--r--md/writeup/assembler_calculate_polynomial.md95
1 files changed, 95 insertions, 0 deletions
diff --git a/md/writeup/assembler_calculate_polynomial.md b/md/writeup/assembler_calculate_polynomial.md
new file mode 100644
index 0000000..8d680a0
--- /dev/null
+++ b/md/writeup/assembler_calculate_polynomial.md
@@ -0,0 +1,95 @@
+title:Assembler calculate polynomial
+keywords:assembler,c,math,polynomial
+
+# Assembler calculate polynomial
+Calculating polynomial with asm and C
+
+```asm
+format ELF
+section ".text" executable
+public poly
+align 4
+poly:
+a equ dword [ebp+8]
+b equ dword [ebp+12]
+c equ dword [ebp+16]
+x equ dword [ebp+20]
+ ;a*x*x+b*x+c
+ push ebp
+ mov ebp , esp
+ fld c
+ fld x
+ fld b
+ fld x
+ fld a
+ fmulp st1 , st0
+ faddp st1 , st0
+ fmulp st1 , st0
+ faddp st1 , st0
+ pop ebp
+ ret
+```
+
+For calculating polynomial used polish notation
+Wiki
+In other words a*x*x+b*x+c to reduce operations changed to (a*x+b)*x+c
+and then written out operation by priorities [*,+,*,+].
+Compiling this with lines
+
+```
+fasm poly.asm poly.o
+```
+
+```c
+#include <stdio.h>
+extern float poly( float , float , float , float );
+int main()
+{
+ float res = poly( 1.0 , 2.0 , 3.0 , 3.0 );
+ printf( "%f\n" , res );
+ return 0;
+}
+```
+
+
+Compiling this with lines
+```
+gcc -c main.c -o main.o
+```
+Combining
+```
+gcc main.o poly.o -o main
+```
+Update on 06.12.2009
+After running dome C code with FPU calculations and -O2 flag
+
+```asm
+format ELF
+section ".text" executable
+
+public poly
+align 4
+poly:
+a equ dword [ebp+8]
+b equ dword [ebp+12]
+c equ dword [ebp+16]
+x equ dword [ebp+20]
+ ;a*x*x+b*x+c
+ push ebp
+ mov ebp , esp
+
+ fld a
+ fmul x
+ fadd b
+ fmul x
+ fadd c
+
+ pop ebp
+ ret
+```
+
+Now only 5 instructions
+
+
+# Links
+http://en.wikipedia.org/wiki/Polish_notation