NO

Author Topic: Declare constant in function body  (Read 3761 times)

CLR

  • Guest
Declare constant in function body
« on: November 20, 2016, 09:57:51 PM »
I wrote the following function with POASM.

Code: [Select]
.data
value REAL8 2.026119

.code

my_cos proc
push ebp
mov ebp, esp

fld qword ptr [value]
fcos

pop ebp
ret
my_cos endp

I wonder if I can declare "value" inside function body.

I tried fld 2.026119 and I got the error "Invalid combination of opcode and operands (or wrong CPU setting)."

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Declare constant in function body
« Reply #1 on: November 20, 2016, 11:09:54 PM »
There is no direct opcode fld 2.026119, but if you prefer this simple syntax to a REAL8 in the .data section, it should be easy to set up a PoAsm macro. Here are some Masm equivalents for your inspiration.

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  fldpi                  ; these are real opcodes
  fldl2e
  fldl2t
  fldlg2
  fld FP8(2.0261191)     ; this is a Masm32 macro
  FpuPush 2.0261192      ; this is a MasmBasic macro
  deb 4, "Fpu", ST(0), ST(1), ST(2), ST(3), ST(4), ST(5), ST(6)      ; use debug macro to display ST(0)
EndOfCode


Output:
Code: [Select]
Fpu
ST(0)           2.026119232177734375
ST(1)           2.026119099999999840
ST(2)           0.3010299956639811952
ST(3)           3.321928094887362348
ST(4)           1.442695040888963407
ST(5)           3.141592653589793238
ST(6)           0.0

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Declare constant in function body
« Reply #2 on: November 20, 2016, 11:38:02 PM »
something to test
Code: [Select]
MVR8 MACRO value
LOCAL varr8
.data
varr8 REAL8 value
.code
EXITM <addr varr8>
ENDM

.code

my_cos proc
.data
value REAL8 2.026119
.code
push ebp
mov ebp, esp

fld qword ptr [value]
fld qword ptr MVR8(2.026119)
fcos

pop ebp
ret
my_cos endp
May the source be with you

CLR

  • Guest
Re: Declare constant in function body
« Reply #3 on: November 22, 2016, 12:46:20 AM »
Thank you for the help, jj2007 & TimoVJL.