Mixing C and asm
Posted: Sat Jan 16, 2016 11:03 pm
Sorry if it has already been asked, but I didn't find 
My game engine is too slow. I'll try to optimize algorithms if possible, but I'm more and more convinced that it won't be enough and that I'll have to code some parts in asm.
I never tried to mix asm and C, and I didn't find examples about how it works. So if someone could show me on simple examples how to do basic stuff in the following situations :
Situation 1 : I want to define a function scmurtz which takes 1 integer and returns 42 if it's greater then 10, or 31 if lower.
What asm code to put in place of dots ?
Situation 2 : I have an already coded (in C) schmurtz function that takes 1 integer and returns one integer. I want to code a zorglub function that takes 1 integer and returns 1 + the result of schmurtz.
Same question.
I think these situations cover most of my needs. I already know the parameters are passed with the stack, but I don't know what to do with output values, nor how to call an external C function.

My game engine is too slow. I'll try to optimize algorithms if possible, but I'm more and more convinced that it won't be enough and that I'll have to code some parts in asm.
I never tried to mix asm and C, and I didn't find examples about how it works. So if someone could show me on simple examples how to do basic stuff in the following situations :
Situation 1 : I want to define a function scmurtz which takes 1 integer and returns 42 if it's greater then 10, or 31 if lower.
Code: Select all
int schmurtz(int a) {
...
}
Situation 2 : I have an already coded (in C) schmurtz function that takes 1 integer and returns one integer. I want to code a zorglub function that takes 1 integer and returns 1 + the result of schmurtz.
Code: Select all
int zorglub(int a) {
...
}
I think these situations cover most of my needs. I already know the parameters are passed with the stack, but I don't know what to do with output values, nor how to call an external C function.