2 ms·
having some trouble keeping track of what I've thrown into what register. As someone who has been writing in Asm for a few decades and taught it briefly at the
by userbinator 10y ago
having some trouble keeping track of what I've thrown into what register.
As someone who has been writing in Asm for a few decades and taught it briefly at the undergrad level, here are a few advices that might help:
Don't move values between registers unless absolutely necessary.
Try to visualise the formation of an expression in a register as instructions operate on it. (E.g. eax holds x+y and ebx holds z; after 'add eax, ebx', eax holds x+y+z.)
If you're doing x86, there's only 8 and one of them (stack pointer) you almost never have to change. That leaves 7, but if you use them according to how they were originally envisioned, then it gets a lot simpler keeping track of the values since their names are mnemonic: EAX is the Accumulator and should be used most of the time. ECX is Count and should be your first choice for a loop counter. EDX is Data and can be treated like a second accumulator. EBX is Base and normally thought of as holding a pointer, same for ESI, EDI, and EBP. The last one is usually used for local variables/parameters on the stack, but for 32/64-bit you can use ESP for stack accesses and put any other "long-lived" address (like a "this" pointer of an object) in EBP.
There are basically no cushy IDEs or other hand-holding things --- Asm is very different from the typical HLL, and mentally executing your code in the editor before assembling and running/debugging is the norm. There is far less "instant gratification", or any "shortcuts". It's just something that you have to practice to become good at.