-
Using asm in C++
Hi, I started coding some asm through C++ so I can optimize my own graphics engine drawing functions. I managed to learn asm and get a nested loop of pixel access and drawing working fully and I can actually see the image result in a window. The render's speed got increased and I'm happy about that. However there's something I don't really understand: why did it work?
To speed my nested loops I thought about moving the most used vars in the registers permanently so it reduces access to ram and stuff. By "why did it work", I mean that since OS are multithreaded and everyprogram need to access and set registers, how can my algorithm worked properly, without having any of the register suddenly get their memory changed?
Is it possible that while running some code in a "_asm" in C++ all other programs are stopped from execution at least until the "_asm" code is done? I don't know much about multithread programming, but I know there are atom, mutex and others concept I don't really understand, that prevents wrong order of execution between programs and common memory.
Hope I'm being clear :)
-
This has nothing to do with whether you write assembly or C++. The compiler takes no specific steps to play nice with other programs either.
This is the business of the operation system. When your thread gets preempted, the OS is responsible for saving its registers, and restoring them just before the thread continues execution. To your thread, it's as if it had never been interrupted.
-
Really, wow then that's great I won't be asking myself tons of questions!
Thanks a lot!
-
hi i need a simple animation using c++, but i dont know how to start. can you help me?
-
Start by not posting in a random thread.
Instead create a new thread, where you elaborate on your question, because as it stands, it doesn't really make much sense.