MIPS vs Intel x86 vs LLVM as the first assembly la

2019-03-29 06:35发布

问题:

Which assembly language should I learn as my first assembly language? MIPS (easier and often used for educational purposes), Intel x86 (omnipresent) or the portable assembly language behind the LLVM project?

One advantage for the LLVM assembly is that I may attempt to use it as a learning exercise to write a simple compiler using LLVM as the backend in the future.

回答1:

None of the above. x86 is the last assembly language you want to learn. MIPS is quite educational for a number of reasons, but it is not a good first instruction set mostly because it is a bit non-standard, doesn't use flags, has branch defer slots, you have to unlearn some things to move to another processor. MIPS maybe second or third.

LLVM isn't really assembly, it is a bytecode. I have one I created just for this, lsasim, search for it at GitHub. Even if you don't actually run the examples, give it a half an hour read or less. It should give a foundation for many other instruction sets. Thumb (without Thumb-2 extensions) is good. MSP430 is really good, LatticeMico8 is pretty good. AVR is not bad. ARM is pretty good. Get comfortable with a couple-three and then MIPS or DLX. x86 should be one of the last, if you even bother. If you bother, learn 8088/86 first then work your way toward the present.

With each instruction set it gets easier, by the third or fourth, you can learn it as you write it, you simply look up the instructions on a quick reference card, occasionally getting detail from a full manual, but mostly just bang out assembly code. At least for the sane ones, there are some you have to do some research to understand all the rules. You don't want to run on hardware for learning these, find a simulator first, hardware later if so desired.

You can use anything as your backend to the front end (actually the middle). Your front end of the compiler should resolve to an internal code, which is not assembly language, then from the internal code to the backend which is target specific (assembly language or machine code). The LLVM middle is published and it is possible to actually use it that way, other compiler middle/internal codes are at best dumped for debugging but not really used as-is. I wouldn't use the assembly education for the middle of a compiler. If you want to write a backend, start with LLVM or something other existing, retargettable compiler, and write a backend to that (the vbcc compiler is a good choice for a first compiler backend, or get the LCC book, or a super simple one: Small-C). If you want to write a front end, for some new or existing language, then LLVM is probably not a bad internal code to use, the backends come as freebies.



回答2:

I started with 8085 microprocessor assembly and then moved on to the 8051 micro-controller.

I then stepped up to 80386 and 80486 micro-processors.

For learning, I think it makes sense to start from the simplest and most basic chip.



回答3:

8085 is the ideal processor to begin with. The fundamentals of most of the instruction sets are pretty much the same. Once you finish 8085, something like the AVR instruction set might be interesting to study (mainly because 8085 is based on von-neumann architecture while AVR has a harvard architecture. Variety).

LLVM .. I won't advice you to learn its assembly language. First of all, the language works on top of a hypothetical architecture which assumes infinite registers and expects an SSA format for the assembly. Note: LLVM is wonderful for writing compilers, but it is definitely not good to start learning assembly level stuff.

The complete x86 instruction set is a bit too complicated to interest anyone. I am sure you would get bored of looking at all the instructions in the set.

Summary: Go for 8085