Almost 40 years ago Intel launched the 80386 microprocessor and, yet, there are lots of people still thinking in terms of the old (1979) 8086. And again, the modern operating systems don't support even the Pentium (1993) aren't supported anymore. So, why bother with these processors and use techniques that were mandatory to them?
Here's an example: Prologues/Epilogues to manipulate stack frames. They existed because the pre-386 processors didn't allow access to the stack via any other registers used as base in an effective address, but just BP. Yep, you couldn't use SP in an address as [sp-4]. This:
; int f( int x ) { return x + 1; }
f:
mov ax,[sp-4]
inc ax
ret
Dont't compile, even today!
386 changed this... you CAN use `ESP` there, in real mode, because in that mode all logical addresses is segment*16+offset, resulting in a 20 bits "physical" address. The address calculation will use only the lower 16 bits of ESP there. This way, proloque/epiloque are obsolete and should be avoided. Why? `push` writes to memory AND decrement ESP. Writing to memory not present in the cache will add a huge penalty to your code... That wasn't a thing in early 8086~80386 processors, but it is in Pentium Pro and newest ones. The newbie tends to automatically insert prologue/epiloque in the function above like this:
f:
; Epilogue
push bp ; Write to the stack.
mov bp,sp ; Copy SP because we can use only BP as base.
mov ax,[bp-8]
inc ax
; Prologue
pop bp ; Restore BP and SP.
ret
When it is way more simple to do:
f:
mov ax,[esp-4]
inc ax
ret
The use of ESP here garantees SS is used as selector. And the resulting code is shorter (and faster)... PUSH/MOV will waste 3 bytes and takes 2~3 clock cycles. POP will waste 1 more byte and waste 2 cycles. In the above function MOV/INC will waste 3 cycles and that's it. The only inconvenience is that MOV AX,[ESP-4] will add a 0x67 (address override) to the instruction.
Of course I'm talking about real mode here. In 386+ protected mode there's no address override.
Another thing about obsolescence is that Intel is preparing to get rid of real/i386 mode of operation (see x86-S specification) in the near future. I don't know if this will happen in the new Core or Core-Ultra processors (generation 14), but it will happen. Take that and the fact not even the Pentium Pro is sold anymore for a couple of decades, that you'll see why programming in assembly as if we are still in the 80's is ridiculous.