Inline Assembly?

This is a discussion on Inline Assembly? within the C++ Programming forums, part of the General Programming Boards category; Is inline assembly generally faster then c++ code. For example is a sorting function written in inline asm faster than ...

  1. #1
    AlenM
    Guest

    Inline Assembly?

    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++?

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    It depends on how good at asm you are.
    zen

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    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.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    Are you using a DOS compiler?
    // Gliptic

  5. #5
    AlenM
    Guest

    Yes

    I'm using Turbo C++ 3.0

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using inline assembly for keyboard input
    By sleventeen in forum C Programming
    Replies: 7
    Last Post: 05-10-2009, 02:31 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  3. Arrays In Inline x86 Assembly
    By saxman in forum C Programming
    Replies: 17
    Last Post: 07-07-2004, 03:38 PM
  4. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  5. inline assembly question
    By DavidP in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2002, 06:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21