Programming with Ones and Zeros
hanshq.net
hanshq.net
I can't remember the exact resource I used for the opcodes and their encodings, but it was the best resource ever. It included cycle information, a description of what the opcode did, and what flags and registers it affected. I haven't been able to find that resource though in a couple years at least. It followed some common template that was used for a number of other topics as well (including DOS interrupts and some obscure programming language)
One of the other fun things I did was craft some self-modifying code... although I once had a bug in it and that was almost impossible to debug
And back in ye old times, the legendary Seymour Cray cold-booted the CDC 1604 for the first time directly from the keys on the front panel before any OS or software existed to run on the machine.
In the System V AMD64 ABI, the first integer argument to a function is passed in the rdi register.
The fib function however, being written for 32-bit mode, is expecting the argument on the stack, and loads it from esp+4, so it gets a garbage value.
The value on the top of the stack is the return address, which is probably somewhere around 0x0000000000400000 (the default entry point). Loading from esp+4 gets the high bits which are all zeros, so that's what goes into %ecx.
If you build the program as a position-independent executable (gcc -fpic -pie), it will get loaded at a random address and it will print a different value.
Well done and presented!
I look forward to going through this in finer detail.