0

In assembly (64 bit) , you can use the inc to increment value in either memory / register. In case of memory, the value is first copied to a "hidden" register and then updated to memory (according to an answer in this question ). But does the same thing happen in case of register

  • 5
    These are internal implementation details and not really relevant to the programmer. The bits are flowing around in the ALU while the addition is being done, but you wouldn't really think of that as a "hidden register". However due to [register renaming](https://en.wikipedia.org/wiki/Register_renaming), an architectural register like `rax` isn't really a single physical register at all, but rather a pointer into a much larger register file, and the output of the `inc` could very well end up in a different physical register than the input. – Nate Eldredge Oct 12 '21 at 17:23
  • 4
    For a memory write, the "hidden register" concept is one way of thinking about why a RMW of memory isn't atomic - other cores can access the memory value in between the read and the right. For a register, the issue doesn't arise because registers are internal to the core and no other core can access them at all. (One thing that is guaranteed is that interrupts do not happen "in the middle of" instructions: every instruction before the pushed program counter will have retired, and every instruction after it will be as if it had not begun.) – Nate Eldredge Oct 12 '21 at 17:27

0 Answers0