Thread: Understanding ASM

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Understanding ASM

    Hi.

    I have close to one year C++ experience and six months MFC experience. I love programming using C++ and enjoy the simplicity MFC brings to Windows programming.

    I will begin my senior year in college this coming fall semester and hopefully, I will fullfil all required courses to graduate spring 2003 and work as a programmer. I am looking at various job descriptions for entry-level programmers especially for C++ programmers. Anyways, I often see ASM in the description. I have no experience with ASM. I will take a required ASM course this fall. Nonetheless, I would like to know some fundamentals of ASM.

    First, I hear about the power of ASM because anything is possible. I hear about ASM being "clean" coding. I know some Java, but have not done any real projects using Java and I do not plan on it either. I think C++ is elite! In real projects including commercial software, games, OS, and the like, how does ASM fit into the equation?

    Basically, I just would like to know at what point do programmers prefer ASM over C/C++? Second, I hear that it is possible to incorporate multiple language when developing one software. How is that possible (especial with C/C++ and ASM)?

    Again, please take into considering that I have no knowledge of ASM and very limited experience with software engineering.

    Thanks,
    Kuphryn

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> at what point do programmers prefer ASM over C/C++?

    No point. Assembler has/had it's uses. People who usually claim assembler has "n" advantages over a modern optimising compiler are living in a golden passed. Unless you actually have to use assembler for a task, you are better off not. Period. Punktum. Full Stop. Assembler programming is always more difficult to understand, more prone to, (disasterous), errors, has big maintenance problems, and tends to be platform specific.

    >>> possible to incorporate multiple language when developing one software.

    With any true compiler, the high level code you write is converted to "assembler", and then onward processed. The intermediate assembler code, (often simply called "object"), is language independent. Thus, a module wriiten and compiled with a C compiler, and a module written with a FORTRAN compiler can be linked together transparently as long as the "calling" convention is agreed in advance. No magic there.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    From a software engineering point of view, ASM is not recommended. You can't write platform independent software or develop easy to maintain and flexible software. And it will take you a long time to code when the project is large. Since ASM software is harder to debug and more sensitive for errors, also the test time will probably be long.

    But it is useful to understand ASM, since it gives you lot of insight in how microprocessors work and it makes you understanding computer architecture.

    In commercial software, I can only speak for embedded systems, there still is a role for ASM. Some very low-level things can only be done in ASM. But modern compilers are so good, that it is usually unnecessary to use ASM for the other things. Those other things are in a lot of cases written in C, C++ or Java or a combination.

    For example, software for a mobile phone: the very low level software, below the OS level and some parts of the OS, are written in assembly. Most of the OS-level is written in C or C++. The applications are written in C++, but more and more applications these days are written in Java. So a Java virtual machine is layed upon the OS level and the applications run on this virtual machine.

    >Basically, I just would like to know at what point do >programmers prefer ASM over C/C++?

    Personally I never prefer ASM over C/C++, but sometimes I can't use C/C++.

  4. #4
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    I propose a deal with all you C/C++ programmers, we all know you are to scared to learn assembly so stop posting a load of bull**** about assembly as a cover-up (not specifically you adrianxw but there are some people on this board who believe that C is the be-all and end-all of computer programming).

    kuphryn assembly most definatly has its advantages, it is increably fast and produces small tight code. It is ideal in games programming where the use of tight loops is nessisary. However it has uses in any algorythm which must exicute at high speed or very often.

    The first assembly comand most people learn is:
    mov dest, source
    This is pretty easy to understand, dest and source can be anyone of the processors registers or a memory location. There are some very good assembly tutorial on the net so try a google search.
    Last edited by VBprogrammer; 07-11-2002 at 03:35 PM.
    VC++ 6

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >assembly most definatly has its advantages, it is increably fast
    >and produces small tight code.

    Sure, it has some advantages, but for commercial software it is not suitable.

    In the mobile phones market, the size and speed of the software isn't the most important thing. More important are things like speed of development, maintainability, flexibility, reusability etc. If your opponents in the market can develop software in a faster and more efficient way and get their product earlier on the market, then you can stop the project. I've been at a project which was stopped after a year because an opponent released its product of the same type two weaks earlier than we planned to do. But because of good software architecture, we're able to reuse the architecture and software components for new products.

  6. #6
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    Shiro - why? What makes assembly so different from every other programming language. If you need part of your program to run fast then code that in assembly, thats pretty simple. I wouldn't recommend assembly for the whole project but for those time critical parts it is unbeatable.The portability of C is always over played as an advantage, in practace changing between different compilers can be pretty difficult.
    VC++ 6

  7. #7
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    >But it is useful to understand ASM, since it gives you lot of insight in how microprocessors work and it makes you understanding computer architecture.<

    This depends on the processor. Learning x86 asm gives limited insight as to how a modern processor using the x86 ISA actually works.

  8. #8
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    Im not really sure what you mean by that Enmeduranki however it easily gives a better insight into how the processor works that C would.

    P.S. I dont really want to turn this thread into yet another C vs ASM argument, all i want to do is help kuphryn understand what ASM is all about.
    VC++ 6

  9. #9
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >What makes assembly so different from every other >programming language.

    The purpose of the language. Most language are written for some special purpose. Assembly is meant to make low-level programming possible. Object oriented languages are meant to make developing object oriented software easier. In my opinion a programmer should use the language which fits the needs. And therefore you should use assembly only to speed-up specific portions of the code or to do some ow-level things.

    >If you need part of your program to run fast then code that in
    >assembly, thats pretty simple.

    If there is a need for speed in parts of the program, one could consider to use assembly. That's correct. I know that a lot of space-, medical- and defense-applications have their time-critical portions of code written in assembly.

    >I wouldn't recommend assembly for the whole project but for
    >those time critical parts it is unbeatable.

    I agree. Note that this is also done, but also note that the size of the critical parts in a project is very small. There usually are just a few places in the software which are time-criticial. But this is usually measured when the code is implemented in C or C++.

    The measurements will show which parts take most of the time and which parts are time-critical. Some research should show that assembly is useful here, in a lot of cases the code an optimizing compiler gives, isn't slower or just less slower than C-code.

    Since hardware is so fast these days and compilers are getting better, these differences are getting smaller and smaller.

    >The portability of C is always over played as an advantage, in
    >practace changing between different compilers can be pretty
    >difficult.

    Also changing assemblers can be real difficult, just compare assembly for Motorola processors with assembly for Intel processors.

    Most C compilers are not compatible and most of them even aren't conform the ANSI C standard. But an advantage of C is that it is more platform independant then assembly. If you use C, then you can more easily switch to a different platform than using assembly, especially when the project is large.

    >This depends on the processor. Learning x86 asm gives limited
    >insight as to how a modern processor using the x86 ISA actually
    >works.

    That's true. Also ASM is different for several processors. But understanding ASM and how a certain processor works, gives you the basic knowledge to study other ASM variants and other processors.

    [edit]
    >P.S. I dont really want to turn this thread into yet another C vs
    >ASM argument,

    I also don't want to argument using C/C++ vs ASM, I'm just explaining why, in my opinion, one should combine the advantages of languages to produce software.
    [/edit]
    Last edited by Shiro; 07-11-2002 at 02:17 PM.

  10. #10
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    >Im not really sure what you mean by that Enmeduranki however it easily gives a better insight into how the processor works that C would.<

    True, but there is alot going on that you never see (register renaming, instruction translation, instruction rescheduling, etc). So your x86 asm program may not actually bear that much resemblance to the finished article. That's not to say there's no benefit though.

  11. #11
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >True, but there is alot going on that you never see (register renaming, instruction translation, instruction rescheduling, etc).

    That's correct, but I wonder if the average programmer needs to know about processors in that detail. I think the level of detail a programmer gets when learning assembly is enough for most tasks. By "know how a processor works", I meant from a software developer point of view, not from a hardware or embedded developer point of view.

  12. #12
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by VBprogrammer
    I propose a deal with all you C/C++ programmers, we all know you are to scared to learn assembly so stop posting a load of bull**** about assembly as a cover-up (not specifically you adrianxw but there are some people on this board who believe that C is the be-all and end-all of computer programming).

    adrianxw assembly most definatly has its advantages, it is increably fast and produces small tight code. It is ideal in games programming where the use of tight loops is nessisary. However it has uses in any algorythm which must exicute at high speed or very often.
    ::WINCE::

    No offecne VB, but from what little I know of Adrian, he was programming in different forms of assembler while you were still collecting teddy bears......

  13. #13
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    Yeah, i figured that out pretty quick (though i dont think i ever collected teddybears so does that make Adrian god?), however i felt it nessisary to give a balanced point of view on the subject of assembly programming. As kuphryn mentioned there are plenty of jobs where experience in assembly ranges from being an advantage to a job requirement.

    Re-reading Adrians post i cant help thinking that those years of programming experience have turned him into the fountain of useless information commonly known as an "Old Fart". Come on, i know that he probably has more computer knowlage in his big toe than i can muster from every last inch of my body, but why doesnt that show in his post?
    Last edited by VBprogrammer; 07-11-2002 at 03:21 PM.
    VC++ 6

  14. #14
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Thanks everyone.

    From all responses and my limited experience, I believe every programming language has/had its imporantance in the world of software design and implementation. I believe C/C++ is currently the most dynamic, most extensible programming language.

    I have seen ASM code of small projects. ASM programming seems redundant when you code certain code many times. Without ASM experience, I am not able to determine what the programmer is doing at each part of the code. I hope to be able to read a ASM source and know exactly what the programmer wants to do. I believe programmers should know a little ASM.

    Oh, this is somewhat off topic, but do software engineers use ASM to develope compilers especially C and C++ compilers?

    Kuphryn

  15. #15
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    Yes and No, it depends on when the C compiler was developed. Obviously if it was developed very early on it will have been developed in ASM (though it may have been developed in Machine Code however this is unlikely). However if it was a modern compiler it is quite possible that the magority of the code was actually developed on another C compiler with ASM being used to speed parts of the code. It is quite possible to develop a compiler in any language but some dont really suit this purpose i.e. writing a C compiler in VB!
    VC++ 6

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. Inline asm
    By wavering in forum C Programming
    Replies: 2
    Last Post: 01-29-2002, 02:42 AM
  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