Thread: Please help me how to implement assembly in C

  1. #16
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    Ya matsp i want to write a inline assembly block which starts from __asm or something like that
    can you please help me now?and suggest me which compiler should i use?and also where link me to few sites which implements assembly in C??

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Visual Studio has ample support (in x86).
    Just type
    Code:
    __asm
    {
    	; Code away!
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, it's not helping that you are using an old compiler, but google found this:
    http://www.gamedev.net/community/for...21&gforum_id=0
    along with many other hits.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    Do we have to include any header files?for that?

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Not inline assembly, no (not for Visual Studio anyway, but I doubt you have to for any other compiler either).
    But Turbo C is a very old compiler and a bad one too. It may have been good in its time, but now it's time to close the lid and move on.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by chottachatri View Post
    Ya matsp i want to write a inline assembly block which starts from __asm or something like that
    can you please help me now?and suggest me which compiler should i use?and also where link me to few sites which implements assembly in C??
    You need a compiler which supports "smart" assembly code, meaning the asm syntax gives you a way to refer to variables and function parameters. Otherwise you are going to have to manually calculate offsets from the base pointer, and your code will break every time you change something.

    Also, writing inline assembly can often lead to slower code, unintuitive as it sounds. Inline assembly code forces the compiler to dump its registers to memory because the asm code you write changes the values of the registers. Thus the compiler can't cache values in registers across your asm block. This often leads to inner loops which are actually slower than if you'd just let the compiler handle it.

    You really should be using assembler ONLY to access system features which can't be accessed with C code. Ideally, write the assembly routines in their own source file and link the C code against it, instead of just dropping instructions inline.

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I will also note that Visual Studio is one IDE and compiler that can handle all this fine.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Elysia View Post
    Not inline assembly, no (not for Visual Studio anyway, but I doubt you have to for any other compiler either).
    But Turbo C is a very old compiler and a bad one too. It may have been good in its time, but now it's time to close the lid and move on.
    Turbo C worked great and still does. All that's wrong with it is that it's 16-bit real mode. But this is not a downside if you WANT 16-bit real mode code.

    In my spare time I hack on my own operating system. The stage2 boot loader is written in 16-bit C which I compile using Turbo C. Best tool for the job. Without it, I'd be stuck writing the boot loader in straight assembly, which believe me, sucks bad.

  9. #24
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    Oh thanks brewbuck it means i dont have to change any compiler right??

  10. #25
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    Well 16 bit is too much, maybe we should go back to straightforward 8-bit coding. Now we would never care about integral sizes any more! Much better and imagine the portability
    In fact high level instructions are just confusing most of the time. A lot of time spent to ponder is my syntax ok here? Since the computational capability of a minimal set of instructions is enough, i believe we should all revert to brain........ :P
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  11. #26
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    Hey you are right !xuftugulus thanks man yo man yo!!

    but from where to get a 8 bit compiler?can you suggest me the links?

  12. #27
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You could always try google: http://www.google.ca/search?q=8-bit+c+compiler
    I see there's a GPL one called anyc.

    But I'm not sure if you really want to be using an 8-bit C compiler or not . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Learning Assembly
    By mrafcho001 in forum Tech Board
    Replies: 5
    Last Post: 03-12-2006, 05:00 PM
  2. C to assembly interface
    By Roaring_Tiger in forum C Programming
    Replies: 4
    Last Post: 02-04-2005, 03:51 PM
  3. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 01:11 PM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 03:35 AM