when i use this function of my library on windows everything works perfectly, but when i tried to port the port to compile with gcc on linux, it compiles and links to the rest of the library fine but it cause my app to crash.

i think i might be this line:

mov eax, DWORD PTR [esi+(edx * 4)] no issues in windows but complains about it being a bad expression, in linux:

Error: bad expression
Error: missing ')'

/*
 * Copies the arguments from the given array to C stack, invoke the
 * target function, and copy the result back.
 */

void asm_dispatch(void *func,
		  unsigned int nwords,
		  char *arg_types,
		  void *args,
		  int res_type,
		  long *resP,
		  int conv)
{
#ifdef WIN32
    __asm {
	mov esi, args
	mov edx, nwords
	shl edx, 1
	dec edx
	test edx, edx
	jz args_done

	// Push the last argument first.
args_loop:
	dec edx
	mov eax, DWORD PTR [esi+(edx * 4)]
	push eax
	jnz args_loop

args_done:
	call func

	// pop arguments
	mov edx, nwords
	shl edx, 2
	add esp, edx

is_stdcall:
	mov esi, resP
	mov edx, res_type
	dec edx
	jge not_p64

	// p64
	mov [esi], eax
	mov [esi+4], 0
	jmp done

not_p64:
	dec edx
	jge not_i32

	// i32
	mov [esi], eax
	jmp done

not_i32:
	dec edx
	jge not_f32

	// f32
	fstp DWORD PTR [esi]
	jmp done

not_f32:
	// f64
	fstp QWORD PTR [esi]

done:
	}
#endif

#ifdef GNUC
	__asm__ __volatile__ (
		".intel_syntax noprefix\n\t"
		"mov esi, %0\n\t"
		"mov edx, %1\n\t"
		"shl edx, 1\n\t"
		"dec edx\n\t"
		"test edx, edx\n\t"
		"jz args_done\n\n"

		"args_loop:\n\t"
		"dec edx\n\t"
		"shl edx, 2\n\t"
		"mov eax, DWORD PTR [esi + edx]\n\t"
		"shr edx, 2\n\t"
		"push eax\n\t"
		"jnz args_loop\n\n"

		"args_done:\n\t"
		"call %4\n\t"

		"mov edx, %1\n\t"
		"shl edx, 2\n\t"
		"add esp, edx\n\n"

		"is_stdcall:\n\t"
		"mov esi, %2\n\t"
		"mov edx, %3\n\t"
		"dec edx\n\t"
		"jge not_p64\n\t"

		"mov [esi], eax\n\t"
		"mov DWORD PTR [esi+4], 0\n\t"
		"jmp done\n\n"

		"not_p64:\n\t"
		"dec edx\n\t"

		"mov [esi], eax\n\t"
		"jmp done\n\n"

		"not_i32:\n\t"
		"dec edx\n\t"
		"jge not_f32\n\n\t"

		"fstp DWORD PTR [esi]\n\t"
		"jmp done\n\n"

		"not_f32:\n\t"
		"fstp QWORD PTR [esi]\n\n"

		"done:\n"
		".intel_syntax prefix"
		: /* no output registers */
		: "r" (args), "r" (nwords), "r" (resP), "r" (res_type), "r" (func)
	);
#endif
}

i dont know how to run a debugger as the app is in java and my library contains a java->c wrapper

btw the original win32 asm was not written by me but taken from sun's jni book

regards, jason

Assembler issue. I don't work in Linux but try...

mov eax, DWORD PTR [esi+edx * 4]

...or some variation of that. Sometimes assemblers get hinky about extra parenthesis. Assembler rules already state that register to left of scalar is scaled!