Tech Support > Microsoft Windows > Development Resources > Asm statements in C
Asm statements in C
Posted by io@uunet2.com on March 9th, 2007


In my program I have

...

for (i=0;i<i2;i++)
{
ii=(short)mylist[i];
asm mov ax,ii;
asm push ax;
}
asm call lpfn2;
...

The lpfn2 is a function address of a dll function.

The compiler I am using next won't take embedded asm (bummer). How would I do
above without asm statements? The number of variable pushed can vary and is
supplied at runtime. How would I declare lpfn2? Currently its void *. To make
matters more difficult lpfn may take different parameters (not just ints)

Posted by matevzb on March 9th, 2007


On Mar 9, 7:11 pm, i...@uunet2.com wrote:
runtime in C, that's why it's assembly code. Your (simple) case above
could pass "mylist" and its size to lpfn2, but then it would only work
for one type.
--
WYCIWYG - what you C is what you get


Posted by Norman Bullen on March 10th, 2007


io@uunet2.com wrote:
Can you change the function that you're calling? If so, instead of a
variable number of arguments, pass an array of void* pointers. Let the
function figure out what type they ought to be and cast the pointers
appropriately.

Norm

--
--
To reply, change domain to an adult feline.


Posted by lallous on March 14th, 2007


Hi

It is okay that the compiler doesn't support ASM directly.

What you can do, is simply construct the ASM code on the fly.

1. virtual alloc and change protection to allow execution
2. generate the needed asm code, by writing to the memory the correct
opcodes (you might need to do some relocation calculations based on the
allocated memory address)
3. call the allocated memory

That should help you out.

--
Elias
<io@uunet2.com> wrote in message
news:d883v2pf8gf39kqd0hnp8chaeol6ctdf10@4ax.com...



Similar Posts