I need to write a procedure in assembler, that calculates the value of a polynomial.
I have two files:
- C source file
- ASM source file
C file:
#include <stdio.h>
#include <stdlib.h>
double func(double,double);
int main()
{
double x=3;
double y=2;
printf("%f\n",func(x,y) );
return 0;
}
ASM file:
.386
.model flat, c
.stack 100h
.DATA
var DW 27
.code
func PROC a:QWORD, b:QWORD
finit
fld b
fld b
fmul
fld b
fmul
fld a
fld a
fmul
fld a
fmul
mov ax, [var]
push ax
fmul
fdiv
fwait
RET
func ENDP
end
What I want to achieve at this stage is value of (b^3) / (27 * a^3).
Probably mov and push are problem’s cause.
As a result I get -1.#IND00
I am on Windows, and using Visual Studio 2012 compiler.
For compilation I use VS2012 command line, and a following bat file:
del *.obj
cl -c poly.c
ml -c poly.asm
cl poly.obj poly.obj
ALSO:
Is there any way to create a procedure with more than 2 arguments?
If you want to load an integer onto the FPU stack you can use
fildcommand. Take also a look for thefimulcommand, with aid of this you can use a integer constant directly for multiplication.Please take care about the stack in your implementation. One way to do simply would be
After the code is done the result will be in
st(0).