Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The problem that i'm having is that I'm trying to do the following in Inline Asm

asd is the address

"call asd"

When viewing it in a hex editor it writes "call dword ptr asd"

I'm quite lost

What I have tried:

I've tried using two things so far in the inline assembly

"call offset asd"

"call asd"

Neither work, I'm missing something and I cant figure out how to go about this
Posted
Updated 6-Oct-18 15:24pm
v2

1 solution

When I am uncertain about the assembly code instructions, I write a snippet of code in C or C++ and then look at the assembly code listing. I did that with this. This code has a simple function and a pointer to it which is called. Here is the assembly code listing :
C++
?DoFunctionTest@@YAXXZ PROC				; DoFunctionTest
; 237  : {

$LN3:
	push	rdi
	sub	rsp, 64					; 00000040H
	mov	rdi, rsp
	mov	ecx, 16
	mov	eax, -858993460				; ccccccccH
	rep stosd

; 238  : 	double x = 16.612;

	movsd	xmm0, QWORD PTR __real@40309cac083126e9
	movsd	QWORD PTR x$[rsp], xmm0

; 239  : 	dblfunc df = factor; // factor is the function, df is a pointer to it

	lea	rax, OFFSET FLAT:?fac@@YANN@Z		; fac
	mov	QWORD PTR df$[rsp], rax

; 240  : 	double result = ( *df )( x );  // call the function - deref the pointer

	movsd	xmm0, QWORD PTR x$[rsp]
	call	QWORD PTR df$[rsp]              ; the actual function call is here
	movsd	QWORD PTR result$[rsp], xmm0

; 241  : 	trace( _T( "DoFunctionTest() - result is %.3f\n" ), result );

	movsd	xmm1, QWORD PTR result$[rsp]
	movq	rdx, xmm1
	lea	rcx, OFFSET FLAT:$SG255887
	call	?trace@@YA_NPEB_WZZ			; trace

; 242  : }
That was the assembly code in debug Unicode 64-bit mode for this code:
C++
double fac( double x )
{
	return 1.0 + x;
}

typedef double ( *dblfunc )( double x );

void DoFunctionTest()
{
	double x = 16.612;
	dblfunc df = fac;
	double result = ( *df )( x );
	trace( _T( "DoFunctionTest() - result is %.3f\n" ), result );
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900