flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
mattst88 24 May 2007, 17:13
fildpi ; loads Pi onto the top of the stack (st0)
fild dword [audio_frequency] ; loads the audio frequency onto the top of the stack (st0), Pi is moved down to st1 fidiv word [channel_phaze] ; converts channel_phaze to a double precision FP value; divide st0 (audio_frequency) by channel_phaze and store results on top of stack (st0) fimul word [frequency] ; converts frequency to a double precision FP value and multiplies st0 by freqency and stores the result in st0 fmul st0,st1 ; multiplies st0 by st1 (pi) and stores the result in st0 fsin ; calculates the sine of st0 in radians and stores the result in st0 fimul word [amplitude] ; converts to double precision and multiplies by st0 storing the result in st0 fistp word [di] ; store the contents of st0 in the memory location [di]; remove st0 from the stack mathematically this performs the following operation di = Amplitude * sin((π * frequency)/channel_phaze) |
|||
![]() |
|
ManOfSteel 25 May 2007, 06:19
It's exactly what I wanted. Thanks very much. Just one more thing, why has pi been moved down to st1? Is it because the "fild" instruction decrements the TOP register pointer?
|
|||
![]() |
|
madmatt 25 May 2007, 11:10
Instead of "fmul st0, st1" you could use the fmulp (with no arguments) this muliplies st0 by st1 and pops the stack then stores the result in st0. Doing this would leave your FPU stack clean for the next operation.
|
|||
![]() |
|
ManOfSteel 25 May 2007, 11:29
thanks madmatt for the optimization
mattst88, shouldn't the operation be rather: amplitude * sin (pi * ((audio_frequency / channel_phaze) * frequency)) or am I wrong? |
|||
![]() |
|
mattst88 25 May 2007, 14:15
Yes, it should. My mistake.
Quote: It's exactly what I wanted. Thanks very much. Just one more thing, why has pi been moved down to st1? Is it because the "fild" instruction decrements the TOP register pointer? Yes, this is exactly what is happening. Since Pi is stored in st0 (the top of the stack) and something else is being pushed onto the stack, Pi is no longer the top. It is now referenced as st1 and the new item is now the top, st0. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.