The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: kyo on August 01, 2007, 10:57:58 AM

Title: FPULIB not working in ObjAsm32
Post by: kyo on August 01, 2007, 10:57:58 AM
today i tried many times to perform arithmatic operation iam using obj classes never matter which operation i do the solution or return is 4211636 eg add , divide, gives the same result i dont know why :dazzled: :eek
Title: Re: FPULIB not working in ObjAsm32
Post by: Biterider on August 01, 2007, 12:01:07 PM
Hi kyo
Can you be more specific on what you are doing? Maybe the code can be helpful to understand the problem.

Regards,

Biterider
Title: Re: FPULIB not working in ObjAsm32
Post by: kyo on August 01, 2007, 12:46:30 PM
i was trying to divide 2 values and get the ratio for autoresizing (iam new bie in asm i have done it before in vb) but the arithmatic operations using fpulib in the objectasm is not working here is a snap sot

Method ProjectASMChatX.OnInitDialog, , wParam:dword, lParam:dword
    SetObject ecx
    invoke GetPostions,[ecx].hWnd
MethodEnd
GetPostions proc  hWnd:HWND
LOCAL M_RECT:RECT
LOCAL M_MAINWINRECT:RECT
LOCAL M_HDW:HWND

LOCAL TMPSTR[512]:BYTE   
;get all the important positions of controls to resize
;MWin_FRM1 CtrlSIZE <>
;MWin_FRM2 CtrlSIZE <>
;MWin_FRM3 CtrlSIZE <>

;MWin_LBL1 CtrlSIZE <>
;MWin_LBL2 CtrlSIZE <>

;MWin_CMD1 CtrlSIZE <>
;MWin_CMD2 CtrlSIZE <>

;MWin_LOG1 CtrlSIZE <>
invoke GetWindowRect,hWnd,addr M_MAINWINRECT ;getmain windows rect

invoke GetDlgItem,hWnd,1001
mov M_HDW,eax
invoke GetWindowRect,M_HDW,addr M_RECT

invoke dwtoa ,M_MAINWINRECT.right,addr TMPSTR
invoke MessageBox,0,SADD("sd"),addr TMPSTR,MB_OK

invoke dwtoa , M_RECT.left,addr TMPSTR
invoke MessageBox,0,SADD("sd"),addr TMPSTR,MB_OK

invoke FpuAdd,888888,34344,addr TMPINT ,SRC1_DIMM or SRC2_DIMM or DEST_MEM

invoke dwtoa ,addr TMPINT,addr TMPSTR
invoke MessageBox,0,addr TMPSTR,addr TMPSTR,MB_OK

;MWin_FRM1.xp

ret
GetPostions endp


every operation of FPULIB failed (i was trying first).
Title: Re: FPULIB not working in ObjAsm32
Post by: raymond on August 02, 2007, 01:45:18 AM
Whenever you use a library of functions, you must first know what parameters are required and what type of results you can expect. The FPULIB is no different and a help file is provided with the library to disclose all the necessary information.

If you do read the description of FpuAdd for example, the 3rd required parameter lpDest is described as follows:

"This points to a TBYTE where the 80-bit REAL result of the addition will be returned. The result can instead be retained on the FPU according to the content of uID. (This parameter is ignored if uID indicates that the result should remain on the FPU.)"

In your instruction
"invoke FpuAdd,888888,34344,addr TMPINT ,SRC1_DIMM or SRC2_DIMM or DEST_MEM"
the TMPINT must thus be a TBYTE variable. If not, because you are only providing a memory address, the function will still store a tbyte value at that address. Later, if you try to use only the first 4 bytes of that value, you cannot expect to have anything close to the correct value.

Furthermore, with the subsequent instruction
invoke dwtoa ,addr TMPINT,addr TMPSTR
you are even attempting to use those first 4 bytes as an integer.

There is a function in the library to store the result of a computation as a 32-bit integer in memory. You may want to try it with code such as follows:
invoke FpuAdd,888888,34344,0 ,SRC1_DIMM or SRC2_DIMM or DEST_FPU  ;leave result on the FPU
invoke FpuRound,0, ADDR TMPINT, SRC1_FPU or DEST_IMEM  ;store it as a rounded 32-bit integer
invoke dwtoa ,addr TMPINT,addr TMPSTR
invoke MessageBox,0,addr TMPSTR,addr TMPSTR,MB_OK


If you want to use a division to get a fractional ratio, you probably do not want that ratio as an integer. You should thus store the computed ratio as a TBYTE and use that accurate ratio for other computations following which you can then store results as integers.

Raymond
Title: Re: FPULIB not working in ObjAsm32
Post by: kyo on August 02, 2007, 07:45:33 AM
Thanks for replay
TMPINT is a TBYTE i dont know why result is comming 4211636 what ever operation i do this result comes (register overwritten  or what i dont know?)
Title: Re: FPULIB not working in ObjAsm32
Post by: raymond on August 02, 2007, 07:39:15 PM
QuoteTMPINT is a TBYTE

But then later, with the instruction
invoke dwtoa ,addr TMPINT,addr TMPSTR
you inform the dwtoa function to treat the value at the TMPINT memory address as a 32-bit integer. :naughty:

The floating point data format is completely different from the integer data format. Which data type and size do you really require at that memory address?

According to the code you posted, the following 10 bytes would be stored at that memory address after adding 888888+34344 on the FPU and storing it as a TBYTE:

00 00 00 00 00 00 66 E1 12 40

The dwtoa should then only use the first 4 bytes (all 0s) and return an ascii 0 for the string being displayed by the MessageBox.

Maybe you should run your code through a debugger to see what is happening at that memory location.

Raymond

P.S. you may also want to check with the author of ObjAsm32 if the FPULIB is compatible with that assembler.
Title: Re: FPULIB not working in ObjAsm32
Post by: kyo on August 03, 2007, 05:47:21 AM
invoke FpuDiv,addr M_MAINWINRECT.right,addr M_RECT.left,addr TMPINT ,SRC1_DIMM or SRC2_DIMM or DEST_MEM
   
i want to get the ration of these to values .eg .23 or .16 etc
Title: Re: FPULIB not working in ObjAsm32
Post by: raymond on August 04, 2007, 02:40:34 AM
If you want to confirm that the FPULIB is functioning correctly, try the following:
.data
  fpuerror db "Invalid operation",0
.code
...
  invoke FpuDiv,addr M_MAINWINRECT.right,addr M_RECT.left,addr TMPINT ,SRC1_DMEM or SRC2_DMEM or DEST_MEM
.if eax != 0
  invoke FpuFLtoA,addr TMPINT,4,addr TMPSTR,SRC1_REAL or SRC2_DIMM
  invoke MessageBox,0,addr TMPSTR,addr TMPSTR,MB_OK
.else
  invoke MessageBox,0,addr fpuerror,0,MB_OK
.endif


BTW, your last posted line of code was giving the address of the sources while you were informing the function that those parameters were the actual values  with the SRCx_DIMM flag. Please read the description of the FPULIB functions carefully to avoid the "garbage-in-garbage-out syndrome.

Raymond
Title: Re: FPULIB not working in ObjAsm32
Post by: kyo on August 04, 2007, 05:15:15 AM
Tried this but not working program crashes. :snooty: i have attached the project plz have look.

[attachment deleted by admin]
Title: Re: FPULIB not working in ObjAsm32
Post by: raymond on August 04, 2007, 03:11:37 PM
At this point, I will have to assume that the syntax of ObjASM for memory operands is identical to the MASM syntax.

In your last attachement, you have the following instruction:

invoke FpuDiv,M_MAINWINRECT.right,M_RECT.left,addr TMPINT ,SRC1_DMEM or SRC2_DMEM or DEST_MEM

According to the MASM syntax, the first two parameters would be the actual values located at the M_MAINWINRECT.right and M_RECT.left memory locations. However, you inform the function with the SRC1_DMEM or SRC2_DMEM flags that the passed parameters are both memory addresses.

The passed parameters most probably have values lower than 1000. When the function tries to read at that memory address, it will definitely be outside your alloted work space and you can be sure that the OS will crash your program.

If ObjASM does not follow the MASM syntax for memory operand references, you will have to review such syntax to make sure you pass the proper parameters and identify them correctly in the flags.

Raymond
Title: Re: FPULIB not working in ObjAsm32
Post by: kyo on August 07, 2007, 02:58:13 AM
Thanks for your response its now working i changed
invoke FpuDiv,addr M_MAINWINRECT.right,addr M_RECT.left,addr TMPINT ,SRC1_DMEM or SRC2_DMEM or DEST_MEM

:bg  :U
sorry for late ans my laptop HDD got crashed.