Using ref and out parameters from inline assembly code

Burton Radons burton-radons at shaw.ca
Tue Feb 12 22:14:59 PST 2008


Harry Vennik Wrote:

> Hi,
> 
> What is the right way to assign a value to a ref or out parameter from inline assembly code?
> 
> Can it just be referenced by its name like any other variable? Or would
> 
> mov EAX, some_out_param
> 
> move the address of the var into EAX? (i.e. out_param being handled as a pointer, and swapping those operands would overwrite the pointer with the value from EAX?)

It's exactly as if it were a pointer in asm, so the move in your case gets the address and you'll need a second move with [EAX] to store or retrieve any value. The only other thing you'll need to watch out for with low-level manipulation of inout/out parameters is that their address is for the object itself, and not the stack:

	extern (C) void func (int a, inout int b, ...)
	{
		// Bad, because that gets the pointer of the next value after whatever b points to.
		auto args1 = cast (void *) (&b + 1);
		
		// Good, but odd.
		auto args2= cast (void *) (&a + 2);
	}

It seems like "&&" should be able to get the pointer to the stack, but it won't.


More information about the Digitalmars-d-learn mailing list