I need to pass a var ( or vars ) from c to asm.
ie:
_SetGMode:
mov ah,0x00
mov al,[var]
int 0x10
ret
and c:
extern void SetGMode( unsigned char var );
SetGmode(0x13);
Thanks
Passing a var from c to asm
Re:Passing a var from c to asm
When your asm function is called, esp will point to the return address. esp + 4 will contain the variable in question. So, off the top of my head:
Or something similar.
Code: Select all
push ecx ; Save this because we'll modify it
mov ecx, [esp + 8] ; + 8 because we have pushed ecx, so 4 + 4 = 8
mov ah,0x00
mov al, cl
int 0x10
pop ecx
ret
Re:Passing a var from c to asm
Thanks its working, now the reverse....i need to pass unsigned char back to the c function.
Re:Passing a var from c to asm
It's the same concept, really--you push the values on the stack. Something like (assuming nasm here):Thanks its working, now the reverse....i need to pass unsigned char back to the c function.
Code: Select all
extern some_c_function
...
some_assembly_routine:
push eax ; Push this as a parameter to the function
call some_c_function
add esp, 4 ; Pop the parameter off the stack
; but since we don't need its value
; we just add 4 to the stack pointer (instead of popping)