Thread: Please help me how to implement assembly in C

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    225

    Please help me how to implement assembly in C

    Hello,
    As we all know C is a middle level language as it does system programming as well as application programming
    I want to know how to implement assembly language in C. How to use popf, push ,mov dest,source all this commands of 8086 in C. Kindly give me the link for this or suggest some good book where i can find these topics!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Depends on the compiler - specify which one(s) you want to use inline assembler with, and I think we can help you.

    --
    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.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    i am using tasm assembler !

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Moved to C programming forum.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    Ok fine sorry for posting it in C++ forum. Now please anybody answer me where can i find it?how to implement assembly in C?atleast give me few good books name or some links?

  6. #6
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Isn't tasm (turbo assembler) an "Assembler"? I think we need to know which C "Compiler" you are using.
    Mainframe assembler programmer by trade. C coder when I can.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So what are you ACTUALLY asking for? How to write inline assembler, how to call C from assembler, how to call assembler from C, or something else?

    Also, I would suggest that you modernize your set of compiler/assembler to something from this century - there are several free of charge options that you could use.

    --
    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.

  8. #8
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by chottachatri View Post
    Hello,
    As we all know C is a middle level language as it does system programming as well as application programming
    I want to know how to implement assembly language in C. How to use popf, push ,mov dest,source all this commands of 8086 in C. Kindly give me the link for this or suggest some good book where i can find these topics!
    Firstly you cannot implement in assembley in C because the are different.
    JHowever you can get you compiler (usually) to produce addembler code if you use the
    correct option (-S ????).
    I think you than can edit that code and assemble it using your c comiler.
    You should themn be able to run it, or not as the case may be.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by esbo View Post
    Firstly you cannot implement in assembley in C because the are different.
    That's not true. You can combine assembly and C/C++.
    Microsoft's Visual Studio, for example, supports inline assembly. GCC if I'm not mistaken, does as well.
    Then you can actually use assembly tools to substitute some source files I think and link 'em together, which just be what you describe.
    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.

  10. #10
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    It is entirely compiler dependent. usually the 'asm', '__asm__' keywords define an inline assembly block where the programmer can use machine dependent assembly instructions. However the programmer also needs to know how to enter outside values to the block, and return values from the block and the compiler uses special syntax to handle such cases. In fact every compiler uses it's own syntax.
    Embedding assembler in C is usually not needed. Trust your compiler it will often do things better. If you need to access hardware, look for libraries that might do your job. If you finally really have to use asm, it can get very exciting.
    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. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by xuftugulus View Post
    Embedding assembler in C is usually not needed. Trust your compiler it will often do things better. If you need to access hardware, look for libraries that might do your job. If you finally really have to use asm, it can get very exciting.
    Obvious exceptions from this rule are when you are writing OS kernels or implementing your own thread-library, virtual machine monitor and similar things.

    You may also need small amounts of assembler to implement certain locking mechanisms - again, this is processor and/or compiler dependant code, so not something most people will be dealing with.

    Finally, it is SOMETIMES possible to implement a better method for some functions in assembler, but for most things, a modern compiler does a better job than us humans.

    --
    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.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you Google for "Crafty", you can d/l a free chess program written by Prof. Robert Hyatt, which includes numerous small functions or loops, in Assembly.

    The program is written in C, though.

    Although it's a long program, the C is very clear, and has itself been described as "An assembly program cleverly masquerading as a C program."

    Enjoy!

  13. #13
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by chottachatri View Post
    Hello,
    As we all know C is a middle level language as it does system programming as well as application programming
    By this argument, assembly is also a "middle level" language because people can, and do, write application programs in assembler.

    In truth, C is a low level language, and about as low as you can get without going to assembly language.

    I want to know how to implement assembly language in C. How to use popf, push ,mov dest,source all this commands of 8086 in C. Kindly give me the link for this or suggest some good book where i can find these topics!
    Mixing assembly language directly into C code can be done with most compilers. Unless you are only doing a single instruction or two, it's better to use a real assembler.

  14. #14
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    Quote Originally Posted by matsp View Post
    Obvious exceptions from this rule are when you are writing OS kernels or implementing your own thread-library, virtual machine monitor and similar things.
    Mats
    Yes of course! It would have to be assembler for such applications, which hupefully you master matsp and all those nice people writing such beautiful code have lifted the burden of our shoulders to do so ourselves, hence my argument.
    I do tinker sometimes with asm, but only a bit, and only for very clear things as it can get confusing to keep track of things at that point.
    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.

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, the whole point of having high(er) level languages is to avoid having to deal with the details of writing it in assembler.

    The key to assembler programing itself is "keep it small" - make small functions or blocks - that way, the complexity of each bit of code is reasonable, and the code can be maintained and understood. [This applies in any language, but it's easy to get carried away in assembler and write long bits of code].

    --
    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.

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