Learning to program in Assembly<>
This question already has an answer here:
It's not as hard as people will tell you. Programming in assembly, at its core, is just writing down a list of instructions (both in the assembly language meaning and the regular one). That makes it conceptually easier than Java, where you have expressions and types and control structures and objects and all sorts of things going on behind your back. In assembly, everything happens exactly the way you wrote it. Even if what you wrote didn't make sense.
Once you wrap your head around that, it's just a matter of learning a huge list of mnemonics and figuring out how to use them effectively.
1. start with value -10 2. add one to the value 3. if the result was not zero, go to step 2
In assembly you could write
mov eax,-10 ; mov is short for move. step_2: add eax,1 jnz step_2 ; jnz is short for jump if not zero
While that doesn't do anything really useful, it illustrates the point that assembly is conceptually easy. The code does exactly what it looks like it should do, and looks exactly like the English description as well. The actually hard part is the same thing as for writing detailed instructions in English - it's easy to get lost when the list of instructions gets complicated.
In case you were wondering "how does jnz know what isn't zero?", that's the job of the "flags". add and many other instructions set certain flags, which jnz and many other instructions can use. One such flag is whether the result of a computation is zero. (that's a bit simplified, but it should do for now)
I recommend a book "Programming from the Ground Up" ,which is intended for beginners interested in assembly programming. It covers the essentials of the basic concept of assembly with examples. I'm reading it now . It is very good !
If you intend to program on x86, you should consider the Intel Manuals. These are really complete and comprehensive (in a first time, you can bypass the System Programming Guide). The first volume named Basic Architecture is probably the best primer I have ever read about computer architecture and assembly. I love the Instruction Set Reference volume, because of the pseudo-code for each instruction which help you to understand what instructions really do.
I recommend starting with instruction set simulators first. 1) possible to get better visibility into what is going on, less frustration starting out 2) easier to boot, less frustration starting out 3) you wont let any smoke out of a simulator, there is an expectation of bricking or smoking boards as you learn on real hardware. I have some simulators http://github.com/dwelch67 plus one (lsasim) that I made just for learning asm, give it a half an hour's worth of running the lessons.
Good instruction sets to start with are msp430, thumb (reduced ARM, the "all thumb variant thumb not necessarily thumb2 extensions), mico8, avr. Simavr is a well known avr simulator, there are many others. skyeye, gdb, qemu have instruction set simulators, there are many others. mame has many you can extract and use, problem is those are written for speed and can be quite difficult to actually extract and use for this. Save x86 for last if you waste your time on it. Save mips for later as well, like the full arm instruction set definitely worth learning but mips is a hardware friendly instruction set at the expense of the software engineers so save it until you have some other experience under your belt. Each instruction set you learn gets easier, much more so than high level programming languages as you learn new ones.
Hardware to go with when you are ready there is an msp430 board for $4.30, cant not get a few at that price. For $20 the stm32f4 discovery is a good purchase. Many flavors of arduinos or other avr boards (the pro micro 3.3v and atmega32u4 board are around $20), go to sparkfun.com for much of this stuff. The mbed platforms are good but on the pricy end, very easy to use. the maple mini is $30 and can use the same dfu-util as the stm32f4 discovery board for loading. do not put all your eggs in one basket, there is a higher level of risk of damaging the board, bricking or smoking, dont buy a $500 whatsit or $250 whatsit instead of 5 $50 whatsits. Get a couple of msp430 boards and say an stm32vl discovery ($10, not to be confused with the stm8 vl discovery).
Java is pretty far removed from assembler. If I were you I would probably start coding something in C++ and then augment that with functions in in-line assembler within the C++ source code. From there, you can move to completely stand-along assembly programs if you so desire.