News:

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

WinApi+Asm Multithreading?

Started by tomson123, February 05, 2012, 03:32:36 PM

Previous topic - Next topic

hutch--

MASM will accept REAL4, REAL8 and REAL10 so its a matter of matching the data SIZE of your C FLOATs to the FP register size in the ASM proc you are calling. I think from memory that a C double is 64 bit (REAL8) but of course you can also pass an address of a C float to an ASM proc as long as you handle the address in such a way as to read the REAL8 value correctly.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

tomson123

I try to pass float and then treat it as REAL4 so the data size is correct i think...
And as I said before, I treat the adress with fld real4 ptr [address].
Let's say I want to pass 5.32.
When I use fild real4 ptr [address] I get 5.
When I use fld real4 ptr [address] I get something like 12733527354

dedndave

you are passing a pointer to the float, correct ?
see if this helps...
        mov     edx,[address]
        fld real4 ptr [edx]

tomson123

Well, to be honest, that's exactly what I'm doing. I'm calculating my address in EAX (adding required offsets to a base address to be in correct place in my array) and then calling fld real4 ptr [eax]. I forgot to mention that "address" was only symbolic... The address is 100% correct (i get 5 when i call fild real4 ptr [eax])

dedndave

no - that does not seem to be correct
FILD loads integers - so the value is seen as an integer   :bg
a dword integer with the value 5 looks like this, in bytes...
        db      5,0,0,0

5.23 looks like this
        db      29h,5Ch,0A7h,40h

if you load that as an integer, it would be 1084709929

i don't read C code very well - lol
it may be you are passing the real4, directly
show us some code - we can't see what you have going on

for REAL4's, it may be prefered to pass the value directly
it sounds like you are passing the address of an array of values
if that's the case, you can't pass directly

tomson123

The most simplified version without unnecessary things would be this:


MyProcedure proc srcArrayPointer: DWORD, dstArrayPointer: DWORD, ...(other parameters)

finit
mov ESI, srcArrayPointer
mov EDI, dstArrayPointer
fld real4 ptr [ESI]
fld real4 ptr [ESI+4]     ;4 byte value
fmulp                         ;now let's say I want to multiply them
fstp real4 ptr [EDI]       ; and store in another array


It isn't obligatory for me to pass the value as float or long or any other 4 byte value, it can be even 8 byte double, just as long as it's floating point.

dedndave

that looks ok
i assume you preserve EBX, ESI, EDI, EBP, if used, though  :P
EAX, ECX, EDX may be trashed

tomson123

It depends what do you mean by "when used".
I keep addresses in them, but when i need them for something else, i push them on stack and pop when i'm done :)
I also do pushad and popad :)
As to my problem, the code below:


mov ESI, srcArrayPointer
fld real4 ptr [ESI]


now returns 1.401e-045#DEN instead of 1(i used a sample value in my program), for whatever reason :/

dedndave

it may simplify your trouble-shooting efforts if you get away from floating point data, for a moment
just pass a pointer - to a string of recognizable text, for example
it will make it easier to see what is passed and what you are getting   :P

you should be able to print out the address of a string in C
then print out the address passed to the routine

it may be that the C code is passing you a pointer to a pointer

dedndave

MyProcedure PROC USES ESI EDI srcArrayPointer:DWORD,dstArrayPointer:DWORD

        mov     esi,srcArrayPointer
        mov     edi,dstArrayPointer
        INVOKE  MessageBox,NULL,uhex$(esi),uhex$(edi),MB_OK
        ret

MyProcedure ENDP


creates a message box
it will have the destination array address in the title bar
and the source array address in the message text

tomson123

I already checked the pointer to a pointer scenario earlier :) It gives me a memory access error, so it isn't a pointer to a pointer :)

EDIT: I feel really stupid asking for this... but could you also write all the necessary code pieces to run a winapi asm program? I haven't played with winapi in assembly yet..
Also, will it be possible to call MessageBox when my main c file from which I call my asm function is a console app?

    include c:\masm32\include\windows.inc   
    include c:\masm32\include\user32.inc
    include c:\masm32\include\kernel32.inc
    includelib c:\masm32\lib\gdi32.lib
    includelib c:\masm32\lib\user32.lib
    includelib c:\masm32\lib\kernel32.lib

The above give me more than 100 errors...

dedndave

if the adresses look kosher, next step:
MyProcedure PROC USES ESI EDI srcArrayPointer:DWORD,dstArrayPointer:DWORD

        mov     esi,srcArrayPointer
        mov     edi,dstArrayPointer
        INVOKE  MessageBox,NULL,uhex$(esi),uhex$(edi),MB_OK
        mov     esi,[esi]
        mov     edi,[edi]
        INVOKE  MessageBox,NULL,uhex$(esi),uhex$(edi),MB_OK
        ret

MyProcedure ENDP

dedndave

yes - you can use MessageBox in a console app

here is a simple console example...
        INCLUDE \masm32\include\masm32rt.inc

        .DATA

szMessage db 'Message',0
szTitle   db 'Title',0

        .CODE

_main   PROC

        INVOKE  MessageBox,NULL,offset szMessage,offset szTitle,MB_OK
        inkey
        exit

_main   ENDP

        END     _main

notice that you should assemble it as a console app:
ml /c /coff MyProg.asm
Link /SUBSYSTEM:CONSOLE /OPT:NOREF MyProg.obj

dedndave

    include c:\masm32\include\windows.inc   
    include c:\masm32\include\user32.inc
    include c:\masm32\include\kernel32.inc
    includelib c:\masm32\lib\gdi32.lib
    includelib c:\masm32\lib\user32.lib
    includelib c:\masm32\lib\kernel32.lib


you are probably missing the processor, model and casemap

have a look at the file:
\masm32\include\masm32rt.inc

it does all that for you

sometimes, you may want to modify it a bit:
        INCLUDE \masm32\include\masm32rt.inc
        .586

tomson123

Alright, it looks like the fun starts for good...
As I said before, it probably isn't a pointer to a pointer, because even trying to mov a second time gives me a memory access error because of trying to read protected memory.
But I tried to display the value under that address in a MessageBox and... I got 00000001!
Seeing as 1.401e-045#DEN is more or less 49, then it looks like i'm getting an ASCII number of my, well, number! O_o

Edit: I have them all except for casemap, which I thought was not necessary.
Edit2: When I try to pass 1.43 it still gives me 00000001... :(