MASM and rand()
Posted 08 April 2004 - 09:15 AM
I wanted to write my newly written raycaster in ASM. To understand whether there is some point in doing that i decided to make this experiment: go to the biggest res supported, create a dib section and fill it every frame with random pixels. I first do it for 10 seconds with C routine and then with assembler one. It's simply a profiler compare after that ;)
and now the real problem:
Iuse MASM to write the ASM routine. Since i need the rand() func for the random pixels i define it's proto in the ASM file:
rand PROTO c
and then simply use it. Upon link with GCC (which links with stdlib) the correct address for the rand function is found and used. __BUT__ - when i call the rand from the C routine everything is fine, when i call it from the ASM routine the app CRASHES?!.
Yes, yes i'm 100% sure that i use the correct calling convention and all addresses are computed correctly. Also i bet five bucks the damn stack frame for the call is correct cause the rand function simply doesn't have any parameters :D
Does anyone have any ideas on this one?
A little hint, the function abs() from the same lib (stdlib that is) is called from the ASM routine correctly.
Posted 06 October 2004 - 03:08 AM
Unfortunatly, in answer to your question, not that Many memories ;)
Posted 06 October 2004 - 04:11 PM
Posted 06 October 2004 - 04:19 PM
Of course, a lot of stuff changed since them and i'm not doing it with FreePascal, which is highly customizable (you can even choose your favorite ASM syntax).
Posted 06 October 2004 - 05:49 PM
Ok let's not start a flame war :blush: i just don't like, it that's all. I'm feeling a lot more comfortable with GCC, FP, Java SE and NASM and Notepad 2 :).
Posted 06 October 2004 - 06:40 PM
Posted 06 October 2004 - 08:15 PM
Posted 06 October 2004 - 09:30 PM
Seriously now, couldn't you just use a debugger, and step through the code in assembly to see what it does and where things go wrong? That would be really easy in Visual Stu... hehe. :blush:
Posted 06 October 2004 - 09:44 PM
Clearly the Intel syntax is superiour. Here the compiler (or should I say assembler) does a lot of work for you. You don't have to 'help it out' with the prepended symbols. It can determine the operand sizes itself, and referencing memory has a clear but flexible syntax.
Why GCC got stuck with AT&T syntax I don't know. It was invented to be able to write a really small parser (read: lazy compiler programmer). But that obvioulsy has no advantage any more today. :dry:
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users