This question might sound very naive, however, I got stuck when one of my friends asked me where can I find the address of an initialized register in the stack.

For e.g., info registers in gdb gives us a list of registers and their corresponding values which are basically stored into it.

Is there any command or way in which I could find the addresses where the registers are actually located? If yes could someone please direct me towards it.

I am glad my friend asked me this question since it was something which I didn't notice earlier because there had not been a time where there was any need of the address where the registers are located.

  • 4
    Registers are on the CPU. Not in the binary – Paweł Łukasik Nov 6 '18 at 6:17
  • Thanks for pointing out @PawełŁukasik, I meant what would be the address in the memory for the registers used in binary. – Jiger Jain Nov 6 '18 at 7:31
  • 2
    @JigerJain I'm fairly certain you may be misunderstanding something here. Registers are named locations of a dedicated size residing in the CPU (as pointed out by Paweł). That is, while the registers comprise a big part of the state of a CPU, they are not on the stack (which is usually in memory). However, you may want to edit your question to explain better what you need. I have a hunch you may be interested in stuff like the return address on the stack or the push-ed register values (not registers). You really need to edit your question to make clear what you want. – 0xC0000022L Nov 6 '18 at 8:39
  • Thanks, @0xC0000022L! (and @PawelLukasik as well) Now I got it, it was a basic understanding of registers on CPU and not the stack! Silly me, nevertheless glad to get a nice explanation. – Jiger Jain Nov 6 '18 at 9:04

Thanks, @0xC0000022L and @Paweł Łukasik.

I got the answer, as you guys pointed out that, registers are on CPU and not in the stack. Which states that it is usually stored in memory and not on the stack.

It was a doubt and I am glad that I got a clarification. Thus would like to post it as an answer.

  • 2
    "On CPU" is not the same as "in memory". The stack is always in memory but the current value of a register – any of them – is not kept in memory. (This is for the common, exact usage of the term 'memory' as an addressable location in ROM or RAM, not something vague-like as "it is what the computer is thinking about".) The "on CPU" that Pawel referred to is, quite literally, on the silicon chip of the CPU itself. – usr2564301 Nov 18 '18 at 20:06
  • @usr2564301 Gotcha! Thanks for the clarification. – Jiger Jain Nov 19 '18 at 0:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.