News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

procedure problem (FPU involved)

Started by learner06, November 22, 2006, 04:19:02 AM

Previous topic - Next topic

learner06

Hi everyone, a newbie to this forum and trying to figure this one out:
I need to write the procedure "Addition" that loads 2 floating point values in ST(0) and ST(1) from my predefined stack and adds them up.

I'm posting the Addition procedure code and my problem is that after the program executes it...there's no result...

;=========================================================================
Push_EBX_to_Stack PROC USES eax edx
    ; This procedure pushes register EBX contents onto a user-defined
    ; stack memory, and increments a count of items on the stack.
   
    mov edx,OFFSET Stack_Array
    mov eax,Stack_Count
    fst  dword ptr [edx+4*eax]                     ; NOT SURE IF fstp or just fst
   
    inc Stack_Count
    ret
Push_EBX_to_Stack ENDP
;=========================================================================

Pop_Stack_to_EBX PROC USES eax edx
    ; This procedure pops register EBX from a user-defined
    ; stack memory, and decrements a count of items on the stack.
   

    mov edx,OFFSET Stack_Array
    dec Stack_Count
    mov eax,Stack_Count
       
    fstp dword ptr [edx+4*eax]                           ;fstp or fst
    mov ebx,[edx+4*eax]
   
    ret
Pop_Stack_to_EBX ENDP

;=========================================================================
;procedure that takes last two pushed items from the stack and ADDS them
;replacing the second one by the result of Addition

Addition PROC USES eax ebx
finit
    ; echo the '+' character:
    call WriteChar
    call Crlf
   
    call Pop_Stack_to_EBX
    mov F_Temp2, ebx
    fild F_Temp2
       
    call Pop_Stack_to_EBX
    mov F_Temp2, ebx
    fild F_Temp2
   
    fadd
    fist Result
    mov ebx, Result
   
   call Push_EBX_to_Stack ; stack <-- value2 + value1
Quit:
    ret

Addition ENDP

"pushing" and "popping" procedure are here too

raymond

Before you attempt to use the FPU, you should have at least some basic knowledge about how it functions and what is the purpose of each instruction specific to the FPU. You should be able to obtain all that information from the following which you can either study on line or download it for your perusal. (If it's for a homework :naughty:, it will give you a tremendous advantage over your classmates. :clap:)

http://www.ray.masmcode.com/fpu.html

If you find it too complicated for immediate use, you also have the option of using the FPULIB available from the same URL.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Mark_Larson

Quote from: learner06 on November 22, 2006, 04:19:02 AM
Hi everyone, a newbie to this forum and trying to figure this one out:
I need to write the procedure "Addition" that loads 2 floating point values in ST(0) and ST(1) from my predefined stack and adds them up.

  I find using scalar SSE instructions much easier than using FP.  You don't have any floating point stack with scalar SSE.  With scalar SSE you operate on one floating point piece of data at a time.  Here's an example moving a value into a register, and adding.


   movss    xmm0,[value1]
   movss    xmm1,[value2]               ;you don't have to specify the amount of data be moving because the instruction tells you.
   addss    xmm0,xmm1
  movss    [result],xmm0


  You don't have to worry about where in the floating point stack you have your values.  And on P4 and up it actually runs faster than FP code.  I am not sure about AMD.
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

learner06

Quote from: raymond on November 22, 2006, 04:53:45 AM
Before you attempt to use the FPU, you should have at least some basic knowledge about how it functions and what is the purpose of each instruction specific to the FPU. You should be able to obtain all that information from the following which you can either study on line or download it for your perusal. (If it's for a homework :naughty:, it will give you a tremendous advantage over your classmates. :clap:)

http://www.ray.masmcode.com/fpu.html

If you find it too complicated for immediate use, you also have the option of using the FPULIB available from the same URL.

Raymond


Thanks for the link and as a matter of fact I have been reading it, I guess just needed to read a bit more :)
Got the thing to work, thanks for replying guys