Slashdot Mirror


Learning x86 for Non-x86 Assembler Programmers?

An anonymous reader asks: "I've done assembler for the 6809, 68000, 8085, MIPS and ARM architectures over the years. But - I've never learned assembler for the most common architecture out there. I would like to change that. I can roughly follow my way around x86 disassemblies, but I'm not as good at optimizing/fine tuning bits of assembler because I am not intimately familiar with all of the addressing modes etc. I would like a book that is targetted at people like me. I would like to be able to fine tune, say a blitter in x86 assembler. One thing I do not in a book is something that is trying to teach me assembler programming in general. Most assembler books seem to fall in the latter category. Are there books out there that might prove useful to me?"

9 of 64 comments (clear)

  1. Helpful website by bdash · · Score: 3, Informative

    A website that could come in handy for learning about x86 assembly language is DDJ Microprocessor Center. In specific, the On-line Intel Documentation links are almost invaluable when learning to code for the x86 architecture. Being Intel reference manuals, they tend to cut to the case relativly quickly.

  2. Too many aspect by e8johan · · Score: 3, Insightful

    I would not recommend anyone to optimize modern x86 asm by hand. If you know your way around disassembled code you know enough to find any (rare) compiler mistakes. Any other operation is usually done better by a compiler. (Please don't yell at me with small, hand optimized special cases, compilers do a good job today if your application isn't very special.)
    If you would try to hand optimize asm code for a modern cpu you must concider many issues, among them the reordering of instruction in the processor, the different layouts of the pipelines in different processor models (even intels differ to other intels), cache effects (I suppose that you must link everything statically and control where in memory your code will end up)...
    You must also unroll loops, change the access patterns to 2D data structures to improve cache performance, avoid inner loop data dependencies, etc. It is simply too much to handle by hand.
    As you probably know a higher level language such as C/C++ and don't write a highly optimized operating system (or work without an OS) you do not need, and should not want to, optimize your asm code by hand!

  3. First, get the reference books by cookd · · Score: 5, Informative

    Shh! It's a secret, but Intel offers 4 very nice books at a great price: free.

    They aren't tutorials, so there isn't the same hand-holding that you would get in a book from Barnes & Noble, but they explain things well enough that a seasoned assembly programmer should be able to follow with no problem at all. I think they are exactly what you want.

    --
    Time flies like an arrow. Fruit flies like a banana.
  4. Re:proccessor that runs 2.5GHz in 640MB ram by Electrum · · Score: 4, Interesting

    Check out MenuetOS, "a fully 32 bit assembly written, graphical OS for asm programming, distributed under General Public License". My friend joked that it ran faster under VMware than Windows does natively.

  5. Zen of Assembly Language by LordNimon · · Score: 3, Informative
    Michael Abrash's The Zen of Assembly Language.

    I'm surprised no one has mentioned this book already, because it's exactly what you're looking for. The only problem is that it's dated - it considers the 80386 to be a new processor. There was a time when no self-respecting assembly programmer would be caught dead without it. Alas, I sold mine a couple years ago, since I already learned everything I could from it.

    The only problem is that it (like all of Abrash's books) has been out of print for a long time, and so it will be very hard to find.

    --
    And the men who hold high places must be the ones who start
    To mold a new reality... closer to the heart
  6. For Linux by cjpez · · Score: 4, Informative

    If you're in Linuxland, you might find linuxassembly.org helpful. I've done some assembly before (only a semester's worth, though), and the site was rather useful to me. If you've never done x86, though, there might not be enough there for you . . .

  7. Re:Assembly on a modern proccessor? by Your_Mom · · Score: 3, Interesting
    *points to the 45-byte guy who was here before him*

    That, is why ASM is better then any HLL. I think the best quote I got from one of my Computer Engineering book was (paraphrasing) "Modern compilers with their optimizations are on the road to becoming almost as good as hand writen assembler."

    Now, would I write word processor in ASM? Not bloody likely, HLLs make it much easier to do. But, when you are writing code for some type of embeded system that doesn't have a whopping 2 GHz processor, ASM will beat any HLL hands down. Unfortunately, too many people think ASM is dead, never learn it, write their embedded code in C and when it isn't fast enough, tell their supervisors that it needs a faster processor. Consider this scenario (stolen from one of my profs):

    • Coder writes embedded system in C.
    • Code isn't fast enough makes company buy faster processor
    • Each processor adds $10 to cost of said system.
    • $10 * 1e6 units = $10e6
    As opposed to this
    • Coder writes embedded system in C
    • Code isn't fast enough
    • Company calls in consultant
    • Consultant reads C, looks at the ASM it creates and spends one night tightening the ASM up.
    • Consultant head off to Florida for the rest of the week
    • At the end of the week consultant makes himself looked disheveled and stumbles in saying "It took all week, but here is the code, it will save to $10 per unit"
    • Consultant Charges $2e6, which will the company gladly pays, considering it saves them over $8e6.
    See, knowing ASM and how processor works is a good thing that can make you money (maybe not as much, but still a nice whopping amount for a few days work). ASM is still needed, and anyone who says different, does not understand how computers work.
    --
    Objects in the blog are closer then they ap
  8. cmp Smaller,Faster by MarkusQ · · Score: 4, Insightful

    And Smaller == Faster.

    Not always. While I have been known to drop into assembly, it should never be the first recourse when you are trying to speed things up. If it is, you are likely to miss out on the biggest savings. My rough priority list:

    1. Find some way to quantify how slow/fast the program is, and where. This might mean using a profiler, but it might not. Slice the data various ways (by high level task, by thread, by low level functions, by data structures accessed, by calling patterns, etc.)
    2. Look closely at the places where the largest chunks of objectionable time are being spent. Consider various refactorings, new algorithms, new data structures, etc. Also look at the customers of the routines in question, to see what their real needs are (e.g. is someone sorting a bazillion data items just so they can pluck the smallest/largest from one end of the structure, or are they recomputing a value that seldom changes) and consider other ways to meet these needs.
    3. Make some test modifications, and repeat
    4. Once you have a good understanding of what the program is doing, and are convinced that it is being done in the most way practical, calculate how long this should be taking. If the actual times are far above your informed estimate, then consider hand coding.

    -- MarkusQ

  9. best x86 resource by green+pizza · · Score: 3, Interesting

    http://grc.com/smgassembly.htm

    Yep, Gibson writes gui Win32 windows apps in pure x86 assembly. He's nuts, but his apps are tiny and run fast. Lots of good resources there.