I'm new and I'm practicing computer science alone as a passion. In assembly a base pointer is used that allows me to refer to a specific memory location by subtracting a certain offset from the base pointer. What is obtained is the absolute address. EBP - offset = absolute address. But where is this subtraction performed?
in which register is the absolute address calculated?
I give a example of my confusion.
If I have MOV dword ptr[EBP], 10
in this case the value of EBP register represent the absolute address.
But if i have MOV dword ptr[EBP - 4], 10
in this case from the ebp address 4 bytes must be subtracted.
In which register is done this operation, where is written the result of this calculation?
If you want the address calculation result in a register, use LEA instead of a load or store, or as well.
When used for actual memory access, address calculation happens inside an AGU in a load or store-address execution unit and is not written back to an architectural register. It's only passed on to the TLB for translation to physical then written to the store buffer. (Or for a load, used to probe L1d cache). This internal addition has some latency and Intel CPUs even try to skip it in some cases, leading to having to replay the uop if they guess wrong. (Is there a penalty when base+offset is in a different page than the base?)
Unlike ARM or a few other ISAs, x86 does not have any addressing modes that write the final address back to the base register.
CPUs are made of a lot of transistors. Some of them are for internal buffers and adders separate from the named registers. The point of addressing modes beyond [reg]
is that you can use them without modifying any of the values you currently have in registers.