Is inline assembly generally faster then c++ code. For example is a sorting function written in inline asm faster than the one written in c++?
Is inline assembly generally faster then c++ code. For example is a sorting function written in inline asm faster than the one written in c++?
The speed difference in that kind of code section would probably not be noticeable. Use inline assembly when you are working with placing graphics on the screen within a critical code section (within a render loop). Also, if you are using a lot of floats it would be better to drop the floats and move to the FPU for your calculations. For instance I used to do bilinear filtering in C code using floats and then using doubles. Neither approach yielded good results. So I scrapped the code and rewrote it for the FPU. Big difference.
For memory accesses the mem.h functions are fast enough to warrant using them rather than coding your own, although there have been occasions where I have. Also there are some things you just cannot do very well or as easily in C since it is a higher level language. In these awkward and rare situations you should use assembly, but these are rare occurrences and would probably only happen if you were developing low-level I/O functions like device drivers and such. It is also a bit harder to do TSRs in C w/o using assembly(keep() does this in C) and sometimes it is difficult to compute the size of the code that will be resident and the part that is transient. For this, you would be better of using assembly and be even better off to use full assembly and not inline as you would have more direct control over your segments.
Also, you cannot access certain registers like cr0 (with good reason) in inline assembly and my compiler/inline assember does not allow me to use 32-bit registers certain opcodes/instructions. For instance stosd is not valid in my inline assembler, but stosw is.
Are you using a DOS compiler?
// Gliptic
I'm using Turbo C++ 3.0
AlenM:
I have merged your new thread with the original. Try to remember to "Reply" rather than "Start New" when continuing an existing thread.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.