Passing parameters to assembler routines. 
Author Message
 Passing parameters to assembler routines.

Hello. I am very new at this, so my question is probably going to be easy. I
am using MS Dev Studio 97 and I am trying pass a parameter to my assembler
function that looks something like this :

.486
cseg segment para public 'code'
assume cs:cseg
public _test1
_test1          proc
                push bp
                mov bp, sp
                mov cx, ss:[ebp+4]
                pop bp
                ret

_test1          endp
cseg            ends
                   end

In the code above I am just trying to get the first parameter of type int
into cx - even that doesn't work (cx does change its value, but not to the
number I specified). What I really need to do is pass a variable by
reference so that I can modify it from the assembler routine. This assembler
routine is in a separate file and I made an .obj file out of it and linked
it using __cdecl convention.
Could anyone please tell me what do I need to do to make this thing work?
Thank you for reading.



Wed, 21 Nov 2001 03:00:00 GMT  
 Passing parameters to assembler routines.
Are you writing 16-bit or 32-bit code? You probably want to write 32-bit
code (if you're using Dev Studio 97) so you should be specifying ebp
instead of bp, ecx instead of cx, etc.

Then, it looks like your error is that the offset you need is [ebp + 8], not
[ebp + 4]. You need to skip over four bytes for the return address and four
bytes for ebp.

If you are passing a value by reference then you are implicitly passing a
pointer.
You might want to explicitly pass a pointer instead, to make it clearer. All
that means is that after going "mov ecx, [ebp + 8]", ecx will contain a pointer
to your value.

As always, stepping through in the de{*filter*} is the best way to clarify this.
Then you can see what value you are loading, and see how close your
desired value is to it.

Quote:

> Hello. I am very new at this, so my question is probably going to be easy. I
> am using MS Dev Studio 97 and I am trying pass a parameter to my assembler
> function that looks something like this :

> .486
> cseg segment para public 'code'
> assume cs:cseg
> public _test1
> _test1          proc
>                 push bp
>                 mov bp, sp
>                 mov cx, ss:[ebp+4]
>                 pop bp
>                 ret

> _test1          endp
> cseg            ends
>                    end

> In the code above I am just trying to get the first parameter of type int
> into cx - even that doesn't work (cx does change its value, but not to the
> number I specified). What I really need to do is pass a variable by
> reference so that I can modify it from the assembler routine. This assembler
> routine is in a separate file and I made an .obj file out of it and linked
> it using __cdecl convention.
> Could anyone please tell me what do I need to do to make this thing work?
> Thank you for reading.

--
.Bruce Dawson, Cavedog Entertainment.
Makers of Total Annihilation - http://www.*-*-*.com/


Thu, 22 Nov 2001 03:00:00 GMT  
 Passing parameters to assembler routines.
You can also mix variable names and assembler code in a .c file:
void test1(int *pInt)
{
    __asm
    {
        // here you can use pInt
        mov eax, pInt    // example
    }

Quote:
}

Have a look at "Accessing C or C++ Data in __asm Blocks" in MSDN.


Fri, 23 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing parameters to assembler routines

2. passing c pointers to assembler routine

3. trouble passing array to inline assembler routine

4. Passing parameter to a _ASM routine

5. Calling a C routine passing binary data parameter

6. Assembler routine in visual c++

7. having trouble with __asm keyword and SIMPLE assembler routine

8. Calling C routines from Assembler...

9. Need parameters for undocumented routine OpenAs_RunDLL

10. wish to pass a routine with arguments to atexit()

11. Passing Arrays to DLL routines written in VC

12. CPrintDialog handle to DLL routine - Invalid once passed

 

 
Powered by phpBB® Forum Software