flat assembler
Message board for the users of flat assembler.
Index
> Windows > Help - Jumping Out of .obj Linked fasm code to C code |
Author |
|
vid 04 Feb 2007, 22:10
if you use statical linking
Code: ;declare C proc in ASM extrn '_hypervistaUnload' as hypervistaUnload ;call C proc in ASM push [DriverObject] ;push argument call hypervistaUnload add esp, 4 ;clear arguments from stack also, if you use C++ compiler, you must enclose definition of "hypervistaUnload" in extern "C" {} block. for more examples, see http://board.flatassembler.net/topic.php?t=6371 also a little "wrath of vid #2", if you are interested. 1. For local labels of procedure, prepend name with ".". This makes it local to label, so you can use same label in more procedures. Example: Code: proc1: .a ; defines proc1.a jmp .a ;jumps to proc1.a proc2: .a ; defines proc2.a jmp .a ;jumps to proc2.a 2. (not that important...) use "retn" instead of "ret". "ret" should be used in procedures, it means something like "return from current context", and since you are out-of-context (not in procedure), it uses retn. so using retn directly is clearer |
|||
04 Feb 2007, 22:10 |
|
HyperVista 04 Feb 2007, 22:49
Thanks vid! I really appreciate the help, and the wrath
I thought declaring the C function as extrn in the fasm code might be the way to go, but wasn't sure. I really appreciate the example. Many thanks professor vid. |
|||
04 Feb 2007, 22:49 |
|
f0dder 04 Feb 2007, 22:52
vid wrote:
IMHO it's better to use 'ret' generally, and 'retn' when you specifically need just that 0xC3 generated (ie., no macro-overloaded 'procedure epilogue code' or whatever). It's like saying "drink coffee with mouth" instead of "drink coffee" - if you choose the first form, people will wonder why you are being so specific if there's not a need for it. Anyway, back to the original question. I don't think you can just call your "DriverUnload" code that way, HyperVista. Rather, you need to exit your DriverInit code returning "failure" - if your C code is mainly a shimmy, your C code could, basically, do "return asm_driverinit(params);", and the assembly code would then return STATUS_DEVICE_CONFIGURATION_ERROR or whatever. |
|||
04 Feb 2007, 22:52 |
|
vid 04 Feb 2007, 23:14
f0dder: usage of "ret" vs. "retn" is really matter of opinion. I find it absolutely the same, it's just that i prefer using native instructions.
of course your point is right about initialization code, but this may been done elsewhere. PS: more "wrath" to come when i am in mood |
|||
04 Feb 2007, 23:14 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.