Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote>However, I really want to learn about assembly, and how it's used in modern day applications.</blockquote> <p>On "normal" PCs it's used just for time-critical processing, I'd say that realtime multimedia processing can still benefit quite a bit from hand-forged assembly. On embedded systems, where there's a lot less horsepower, it may have more areas of use.</p> <p>However, keep in mind that it's not just "hey, this code is slow, I'll rewrite it in assembly and it by magic it will go fast": it must be carefully written assembly, written <em>knowing</em> what it's fast an what it's slow on your specific architecture, and keeping in mind all the intricacies of modern processors (branch mispredictions, out of order executions, ...). Often, the assembly written by a beginner-to-medium assembly programmer will be <em>slower</em> than the final machine code generated by a good, modern optimizing compiler. Performance stuff on x86 is often really complicated, and should be left to people who know what they do => and most of them are compiler writers. :) Have a look at <a href="http://blogs.msdn.com/b/oldnewthing/archive/2004/12/16/317157.aspx" rel="noreferrer" title="Optimization is often counter-intuitive - The Old New Thing">this</a>, for example.</p> <blockquote>I know processors have different instruction sets above the basic x86 instruction set. Do all assembly languages support all instruction sets?</blockquote> <p>I think you're confusing some things here. Many (=all modern) <code>x86</code> processors support additional instructions and instruction sets that were introduced after the original <code>x86</code> instruction set was defined. Actually, almost all x86 software now is compiled to exploit post-Pentium features; you can query the processor to see if it supports some features using the <a href="http://en.wikipedia.org/wiki/CPUID" rel="noreferrer">CPUID</a> instruction. Obviously, if you want to use a mnemonic for some newer instruction set instruction your assembler (i.e. the software which translates mnemonics in actual machine code) must be aware of them.</p> <p>If, instead, you're talking about other (non-x86) instruction sets for other families of processors, well, each assembler should support the instructions that the target processor can run. Not all the instructions of an assembly language have direct replacement in others, and in general porting assembly code from an architecture to another is usually a hard and difficult work.</p> <blockquote> How many assembly languages are there?</blockquote> <p>Theoretically, at least one dialect for each processor family. Keep in mind that there are also different notations for the same assembly language; for example, the following two instructions are the same x86 stuff written in AT&amp;T and Intel notation:</p> <pre><code>mov $4, %eax // AT&amp;T notation mov eax, 4 // Intel notation </code></pre> <blockquote> How would someone go about writing a routine in assembly, and then compiling it in to object/binary code?</blockquote> <p>If you want to embed a routine in an application written in another language, you should use the tools that the language provides you, in C/C++ you'd use the <code>asm</code> blocks.</p> <p>If you, instead, wanted to write a whole application in assembly, you'd have to write just in assembly, following the syntactic rules of the assembler you'd like to use.</p> <blockquote>How do we know the code we've written in assembly is the fastest it possibly can be?</blockquote> <p>In theory, because it is the nearest to the bare metal, so you can make the machine do just exactly what you want, without having the compiler take in account for language features that in some specific case do not matter. In practice, since the machine is often much more complicated than what the assembly language expose, as I said often assembly language will be slower than compiler-generated machine code, that takes in account many subtleties that the average programmer do not know.</p> <hr /> <h3>Addendum</h3> <p>I was forgetting: knowing to read assembly, at least a little bit, can be <em>very</em> useful in debugging strange issues that can come up when the optimizer is broken/only in the release build/you have to deal with heisenbugs/when the source-level debugging is not available or other stuff like that; have a look at the comments <a href="http://blogs.msdn.com/b/oldnewthing/archive/2004/11/11/255800.aspx" rel="noreferrer" title="Advantages of knowing your x86 machine code - The Old New Thing">here</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload