what does the assembly instruction ‘db’ actually do?
It literally places that byte right there in the executable.
It literally places that byte right there in the executable.
See Why Does GCC LEA EIZ?: Apparently %eiz is a pseudo-register that just evaluates to zero at all times (like r0 on MIPS). … I eventually found a mailing list post by binutils guru Ian Lance Taylor that reveals the answer. Sometimes GCC inserts NOP instructions into the code stream to ensure proper alignment and … Read more
One significant difference between LEA and ADD on x86 CPUs is the execution unit which actually performs the instruction. Modern x86 CPUs are superscalar and have multiple execution units that operate in parallel, with the pipeline feeding them somewhat like round-robin (bar stalls). Thing is, LEA is processed by (one of) the unit(s) dealing with … Read more
esp is the stack pointer, ebp is/was for a stack frame so that when you entered a function ebp could get a copy of esp at that point, everything on the stack before that happens, return address, passed in parameters, etc and things that are global for that function (local variables) will now be a … Read more
If your modulus / divisor is a known constant, and you care about performance, see this and this. A multiplicative inverse is even possible for loop-invariant values that aren’t known until runtime, e.g. see https://libdivide.com/ (But without JIT code-gen, that’s less efficient than hard-coding just the steps necessary for one constant.) Never use div for … Read more
When you do a cmp a,b, the flags are set as if you had calculated a – b. Then the conditional jump instructions check those flags to see if the jump should be made. In other words, the first block of code you have (with my comments added): cmp al, dl ; set flags based … Read more
enter is avoided in practice as it performs quite poorly – see the answers at “enter” vs “push ebp; mov ebp, esp; sub esp, imm” and “leave” vs “mov esp, ebp; pop ebp”. There are a bunch of x86 instructions that are obsolete but are still supported for backwards compatibility reasons – enter is one … Read more
an actual answer for you: Intel 64 and IA-32 Architectures Optimization Reference Manual Section 3.5.1.7 is where you want to look. In short there are situations where an xor or a mov may be preferred. The issues center around dependency chains and preservation of condition codes. In processors based on Intel Core microarchitecture, a number … Read more
mov esp,ebp sets the stack pointer to the base frame address, effectively releasing the whole frame. (Don’t forget that this is Intel syntax, the destination comes first.) If you didn’t do it, once you call ret, you would still be using the called function’s stack frame with your calling function, with crashtastic consequences.
Most Windows process (*.exe) are loaded in (user mode) memory address 0x00400000, that’s what we call the “virtual address” (VA) – because they are visible only to each process, and will be converted to different physical addresses by the OS (visible by the kernel / driver layer). For example, a possible physical memory address (visible … Read more