Calling SDL/OpenGL from Assembly code on Linux
Posted
by Lie Ryan
on Stack Overflow
See other posts from Stack Overflow
or by Lie Ryan
Published on 2010-06-12T14:06:15Z
Indexed on
2010/06/12
14:12 UTC
Read the original article
Hit count: 287
I'm write a simple graphic-based program in Assembly for learning purpose; for this, I intended to use either OpenGL or SDL. I'm trying to call OpenGL/SDL's function from assembly.
The problem is, unlike many assembly and OpenGL/SDL tutorials I found in the internet, the OpenGL/SDL in my machine apparently doesn't use C calling convention. I wrote a simple program in C, compile it to assembly (using -S switch), and apparently the assembly code that is generated by GCC calls the OpenGL/SDL functions by passing parameters in the registers instead of being pushed to the stack.
Now, the question is, how do I determine how to pass arguments to these OpenGL/SDL functions? That is, how do I figure out which argument corresponds to which registers?
Obviously since GCC can compile C code to call OpenGL/SDL, so therefore there must be a way to figure out the correspondence between function arguments and registers. In C calling conventions, the rule is easy, push parameters backwards and return value in eax/rax, I can simply read their C documentation and I can easily figure out how to pass the parameters. But how about these?
Is there a way to call OpenGL/SDL using C calling convention?
btw, I'm using yasm, with gcc/ld as the linker on Gentoo Linux amd64.
© Stack Overflow or respective owner