fpu programming (in real mode)

Programming, for all ages and all languages.
Post Reply
thekeyboardbum
Posts: 4
Joined: Sat Jun 30, 2007 10:11 pm

fpu programming (in real mode)

Post 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
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: fpu programming (in real mode)

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post 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.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
thekeyboardbum
Posts: 4
Joined: Sat Jun 30, 2007 10:11 pm

Post by thekeyboardbum »

Thanks a bunch =D
Post Reply