Search code examples
assemblycpulow-level

Some general information about assembly


I accidentally ended up here: http://altdevblogaday.com/2011/11/09/a-low-level-curriculum-for-c-and-c/, and it turned out to be one of the most informative collection of stuff I have read so far. I knew that assembly was some kind of a low level language that can be executed directly by a processor, but, I also read that each processor has it's own assembly.

Questions:

  • Is this true?
  • Will I be able to run some basic assembly on both my netbook and my PC?
  • Is the only difference between, say, AVRs (who use the RISC architecture) and x86 processors who use the CISC, the instruction set they use?
  • How do you run assembly code and in what kind of files do you store it?

Solution

    1. Yes, to an extend. Although two processors from the same family might have different assembly languages, in reality one language may be an extension of the other. Sometimes processors from different manufacturers (e.g. Intel and AMD) share a great deal of their instruction set. Moreover, in spite of the vast number of assembly languages out there, they all share a relatively small number of fundamental concepts. Once you learn to program in one assembly language, learning a second one is usually an order of magnitude easier undertaking. Of course there are exceptions to this rule: for example, learning an assembly for a CPU that follows Harvard architecture is slightly trickier than learning your second Von Neumann assembly. Switching between RISC and CISC may present challenges as well.
    2. It depends: if your PC and your netbook have CPUs from the same family, you may get lucky. There's more than the instruction set to being able to run an assembly language program, though: the operating system matters a lot, too. For example, Linux and Windows do not share the same format of executable files.
    3. There is a lot more to hardware than the instruction set. There are CPUs with identical instruction sets that use very different hardware. The classic example is 8088 vs. 8086: their instruction sets are identical, but their hardware differs rather fundamentally because of the width of their external data bus.
    4. You run assembly code by first compiling it, the same way you do your C programs. .asm is a typical extension for your assembly programs, but it's far from being a universal rule. You can also embed assembly into your C/C++ files using compiler-specific extensions.