Does anyone have a recommendation for an IDE or debugger that can let me inspect my registers at a given step of the program?
Does anyone have a recommendation for an IDE or debugger that can let me inspect my registers at a given step of the program?
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.
I first started writing code in notebooks due to necessity (I grew up in a poor family, and though I had access to many outdated programming books at my local library, I rarely had access to a computer), but I keep doing it nowadays because it's utterly distraction-free, and being able to scribble notes and diagrams in the code is often convenient.
For assembly language especially, I find the two-column format indispensable. Even when I got to university and took an assembly language class, I would write all my assignments in vim with soft tabstops set to the middle of the screen[1], so that after each instruction, I could hit tab and my cursor would instantly be at the second column for commentary. I know emacs can do something similar, because I managed to get it stuck on in lisp-mode before, and couldn't figure out how to turn it off! :)
[1]:
au FileType asm setlocal sts=38 et " GNU as
au FileType nasm setlocal sts=38 et " nasm
Vim has syntax files for a whole bunch of assembly instruction sets and syntaxes, which I've found handy. (lldb) register read
General Purpose Registers:
rax = 0x0000000000000001
rbx = 0x0000000000000000
rcx = 0x00007fff5fbff8c8
rdx = 0x00007fff5fbff780
rdi = 0x0000000100000f2a "sizeof(char): %zu\n"
rsi = 0x0000000000000001
rbp = 0x00007fff5fbff750
rsp = 0x00007fff5fbff730
r8 = 0x0000000000000000
r9 = 0x00007fff790620c8 atexit_mutex + 24
r10 = 0x00000000ffffffff
r11 = 0xffffffff00000000
r12 = 0x0000000000000000
r13 = 0x0000000000000000
r14 = 0x0000000000000000
r15 = 0x0000000000000000
rip = 0x0000000100000e66 a.out`main + 22 at sizeof.c:4
rflags = 0x0000000000000206
cs = 0x000000000000002b
fs = 0x0000000000000000
gs = 0x0000000000000000
gdb's equivalent should be `info registers`. (gdb) help si
Step one instruction exactly.
(gdb) help ni
Step one instruction, but proceed through subroutine calls.
(gdb) help info registers
List of integer registers and their contents, for selected stack frame.
Register name as argument means describe only that register.
(gdb) layout reg # to enable view of registers in split screen
Also, you can use register names in expressions. e.g. p $r11All of this is applicable when debugging a C program as well.