1. Calling a euphoria func from asm

I've been trying to call a function written in euphoria from some asm 
code, though I've had little success. I'm first trying to call a func 
with no arguments, and I'll expand it later. Here's the code:

include machine.e
include dll.e
include asm.e
atom caller, hiproc

function HelloWorld(integer a)
    puts(1, "Hello World!\n")
    return 0
end function

hiproc = call_back(routine_id("HelloWorld"))
caller = get_asm("pushad\n" &
                 "call near #" & sprintf("%x", hiproc) & "\n" &
                 "popad\n" &
                 "ret")

call(caller)

if wait_key() then end if


As far as I know, nothing should be pushed when calling a function which
doesn't have any arguments. I've looked up the calling convention and
I've not found any info about something that should be pushed in this 
case. An interesting thing is that if you change "call(caller)" to
"call(hiproc)" you'll get the "Hello World" printed, though the program
crashes after that. Maybe because of that call() doesn't save any 
registers?

Regards, Alexander Toresson

Shhh! Be vewy quiet! I'm hunting wuntime ewwows!

new topic     » topic index » view message » categorize

2. Re: Calling a euphoria func from asm

Alexander Toresson wrote:
> 
> I've been trying to call a function written in euphoria from some asm 
> code, though I've had little success. I'm first trying to call a func 
> with no arguments, and I'll expand it later. Here's the code:

<snip>

> As far as I know, nothing should be pushed when calling a function which
> doesn't have any arguments. I've looked up the calling convention and
> I've not found any info about something that should be pushed in this 
> case. An interesting thing is that if you change "call(caller)" to
> "call(hiproc)" you'll get the "Hello World" printed, though the program
> crashes after that. Maybe because of that call() doesn't save any 
> registers?

A standard call_back() like you've done results in a stdcall function.
This means that the callee will clean up the stack.  So what's happening
here is that the Eu routine is poping the return address rather than the
value passed for the routine's parameter, and the result is a machine
crash.  I'm not sure why call(caller) doesn't work, but I suspect that
the problem is that you're not using an immediate addressing mode (or 
whatever).  I've usually used pointers to routines.

I've written a lib that uses asm to call routines by reference.  You
can get it from:

http://www.rapideuphoria.com/fptr.zip

I don't claim that it's great asm, but it works.

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

3. Re: Calling a euphoria func from asm

Hello there,

I've modified Matt's original file to provide a 
stdcall() without having to reverse the params
if it's any help.  It's a free file included with
the WinClass Library, i think it's "stdcall.e".
It's a stand alone file so you can use it by
itself without using any WinClass stuff.

Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu