Hi,
Some generic advice:
- for all languages, formatting/style is important. For assembly this means labels should be as far left as possible, instructions should be indented once and any comments should line up in a column on the right.
- for assembly, (unlike high level languages where there is meaningful variable names) you use registers for a lot of things and the register name doesn't tell you much about what the value is meant to be (e.g. "EAX" could be a pointer to a file name as an ASCIIZ string or the price of a goat in Alaska). This means that comments are very important in assembly.
- for assembly, you tend to use instructions for their effect rather than their semantic meaning. For example, "lea eax,[ebx+273]" looks like it loads the effective address of something into EAX (e.g. maybe EBX is the address of a structure and you want a pointer to a field in that structure), but it could just as easily be code to convert degrees Celsius into degrees Kelvin that has nothing to do with loading an effective address at all. This means that comments are very important in assembly.
- for all languages there are only 2 kinds of bugs. The first kind of bug is code that doesn't do what the programmer intended it to do. The second kind of bug is code that does do what the programmer intended it to do (but the programmer's intentions were wrong). For assembly, "debugging" often means checking that the comments (which describe the programmer's intent) do describe a sane/correct algorithm without looking at the instructions at all; and then checking that the instructions actually do what the programmer intended. Basically; this means that comments are very important in assembly.
Of course (just like other languages) some things are so obvious that comments aren't need. One example of this would be setting up a "C style" stack frame, which is something that all assembly programmers should recognise easily without any comments. Ironically, for "pure assembly" code (e.g. a boot loader) setting up a stack frame is also an unnecessary waste of time.
Now, here's some example code:
Code: Select all
first:
push ebp
mov esp, ebp
mov al, 0x0F ;al = the size of your dog's testicles
mov bl, 0x0F ;bl = the size of your cat's testicles
cmp al, bl ;Are your dog's testicles the same size as the cat's testicles?
jne next ; no, get the dog and the cat neutered
; yes, get the dog and the cat neutered
next:
andyharglesis wrote:All in all, do you think I'm "ready" for this yet?
No you're not ready; but neither am I, and neither is Linus Torvalds, Andrew Tanenbaum, Steve Jobs or Brian Kernighan. Nobody ever is, partly because the goalposts keep shifting (e.g. if you waited until you were ready, then "ready" would change and you wouldn't be ready).
Cheers,
Brendan