Thread: Using asm in C++

  1. #1
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114

    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

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Really, wow then that's great I won't be asking myself tons of questions!
    Thanks a lot!

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    1
    hi i need a simple animation using c++, but i dont know how to start. can you help me?

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc asm code syntax
    By Uberapa in forum C Programming
    Replies: 4
    Last Post: 06-15-2007, 01:16 AM
  2. Asm + C++
    By JaWiB in forum C++ Programming
    Replies: 17
    Last Post: 06-26-2003, 03:13 PM
  3. Understanding ASM
    By kuphryn in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 07-12-2002, 07:39 PM
  4. asm mov
    By manu in forum C++ Programming
    Replies: 1
    Last Post: 12-15-2001, 12:59 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM