Anyone good with assembly?
Page 1 of 1
MirkoOdora




Posts: 1031

PostPosted: Mon, 9th Aug 2010 19:31    Post subject: Anyone good with assembly?
If there's anyone here good with x86 assembly, please help!

In a nutshell I need a single assembly function that will:

1. Take a list of parameters for the method pointer to be called and put them into registers in the right order.
2. Call the method pointer.
3. Return the optional result of the method pointer call.

It's for a VM/script interpreter for a game engine I'm working on.

I'll give more details if needed.
Back to top
Rinze
Site Admin



Posts: 2343

PostPosted: Tue, 10th Aug 2010 22:11    Post subject:
Why would you want to do that in assembly? Just use the same programming language you use for the rest of your program.

And you say you call the the function with the right parameters, then why couldn't you call the method pointer directly as it takes the same parameters in the same order?
Back to top
MirkoOdora




Posts: 1031

PostPosted: Tue, 10th Aug 2010 22:53    Post subject:
I've opted for a different solution in the meantime but here's what I had in mind earlier:

I'd parse the script into structures similar to this:

struct FUNCTION_CALL {
string: NameOfTheFunctionToCall;
strings[]: Parameters;
};

I'd look up the address (untyped pointer), parameter list and parameter types of the FUNCTION_CALL.NameOfTheFunctionToCall from a list of funcs available to script.

Finally I would convert the parameters from that array of strings I parsed from the file and put them into registers prior to calling the function via assembler.

No RTTI was involved in this option, but I've opted for RTTI in current implementation with classes and inheritance and I can do a lot more and with less code. It's more of compiled code and potentially slower but fuck it.


Asus, B550, 3700X, 3060, 32GB.
Back to top
tainted4ever
VIP Member



Posts: 11335

PostPosted: Tue, 10th Aug 2010 23:30    Post subject:
Needs more detail. I'm still unclear on what's going on.


Sense Amid Madness, Wit Amidst Folly
Back to top
Rinze
Site Admin



Posts: 2343

PostPosted: Wed, 11th Aug 2010 06:05    Post subject:
So Delphi? Delphi supports function and method pointers, so you don't need assembly for that. But in either way what you're doing is an unusual way of implementing a script interpreter, your tokenizer will give you bunch of function tokens, you can/should use regular code to determine what function to call. You're not going to be compiling functions defined in scripts, so the function list stays the same anyway, no need to complicate things with a list of functions and parameter types.
Back to top
MirkoOdora




Posts: 1031

PostPosted: Wed, 11th Aug 2010 15:31    Post subject:
Yeah, but because Delphi is so strongly typed it's actually quite difficult to design a generic function which would call compiled functions based on what was read from the file.

For each function that is available to scripting I would also need to declare:

TMyScriptFunction1 = function(aParam: integer): byte; of object;

and then use a HUGE case/switch statement or something to check what function to call based on what was read from the script.

That's why I wanted to hack it and write less code.


Asus, B550, 3700X, 3060, 32GB.
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group