Page 1 of 1

fpu programming (in real mode)

Posted: Mon Jul 16, 2007 2:06 am
by thekeyboardbum
So i have a quick function...why dosen't this work?

Code: Select all

mov ax,01
push ax
mov bp,sp
fild word [ss:bp]
mov word [ss:bp],0
fistp word [ss:bp]
[ss:bp] stays to be 0. When i check the fpu status flags after fild i got

Code: Select all

1000001011000001

Re: fpu programming (in real mode)

Posted: Mon Jul 16, 2007 3:40 am
by Brendan
Hi,

This looks like you've got an invalid operation and a stack fault (where "stack fault" means the stack of FPU registers, not the CPUs stack, and has nothing to do with SS:SP or SS:BP).

I'm guessing the FPU was in it's power on state (with all FPU registers set to zero and not empty), and the first FILD tried to load a new value into the FPU register stack and the FPU register stack was full. I'd also guess that it'd work fine if you started with a FINIT instruction (or perhaps a FNINIT)... ;)


Cheers,

Brendan

Posted: Mon Jul 16, 2007 6:57 am
by XCHG
You don't have to load the value of 1 into a General Purpose Register and then transfer it to an FPU stack slot. You can use the FLD1 instruction that automatically does that for you in the FPU.

Code: Select all

  FINIT
  FLD1
  MOV     BP , SP
  SUB     SP , 0002h
  FISTP   WORD PTR [BP - 02h]
  MOV     AX , WORD PTR [BP - 02h]
  ADD     SP , 00002h
AX will then be equal to 0001h. Below is the modified version of your own program:

Code: Select all

  MOV     AX , 0001h
  PUSH    AX
  MOV     BP , SP
  FILD    WORD PTR [BP]
  MOV     WORD PTR [BP] , 0000h
  FISTP   WORD PTR [BP]
  POP     AX
Good luck.

Posted: Mon Jul 16, 2007 12:56 pm
by thekeyboardbum
Thanks a bunch =D