10

I am just starting to learn Assembly (I have worked with before).

I am wondering why do we need to use registers in addition to using memory, why not just use memory?

I guess the most obvious reason is that doing calculations in a register is much faster than doing calculations in memory. But is this the only reason?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user8437463
  • 357
  • 3
  • 6
  • I wasn't totally satisfied with the answers here or on the duplicate I found (especially for this version of the question), so I posted https://stackoverflow.com/questions/2360997/assembly-why-are-we-bothering-with-registers/45603798#45603798. One of the more important differences between registers and memory is that register numbers have to be hard-coded into the machine-code, not indexed, so the CPU always has them right away. x86 is designed as a register machine, originally for code-density reasons I assume. That allows high-performance implementations. – Peter Cordes Aug 10 '17 at 03:12

0 Answers0