0
$\begingroup$

From my understanding, a CPU register is a temporary storage or working location built into the CPU itself. The CPU includes some functional units such as the ALU (which is part of the chip, as far as I know).

In a 64 bit architecture, we have 16 general purpose registers, that seem to be often used in ASM programs to store temporary values. Going from high to low level, a program is translated to machine code and interpreted by the computer, that executes the instructions.

But if every operation is a kind of arithmetic one, are all of them done using these general purpose registers, taking into account that programs generally need some kind of "temporary" storage for their calculations to be performed? Are they kind of "buffers" for every mathematical operation the CPU needs to calculate?

Do every computation in a CPU needs to be done using registers to place values?

$\endgroup$
1
  • $\begingroup$ Are you asking about the internal workings of a CPU, or the way it is programmed? $\endgroup$
    – user253751
    May 10 at 10:42

2 Answers 2

1
$\begingroup$

Yes and no.

Ignoring special-purpose CPUs (e.g. stack machines, which still matter), most instruction set architectures (ISA for short) fall into one of two fuzzy categories:

  • Load/store architectures, such as ARM, have separate memory instructions (i.e. loads and stores) and ALU instructions.
  • Register-memory architectures, such as Intel x86, have ALU instructions that can take a memory location as an operand. Note that the more recently-designed parts of Intel's ISA, such as SSE, follow the load/store approach more closely.

The way that CPUs work internally is more complex. Modern CISC CPUs such as Intel tend to translate programmer-visible instructions into lower-level operations that are more load/store in nature; Intel calls these "micro-ops", or uops for short. This may require "extra" temporary registers, but register renaming means that this is probably also true of the general-purpose registers that a programmer sees.

$\endgroup$
0
$\begingroup$

First, there are many more registers in a modern CPU than the ones that are visible to the program. Your iPhone has about 500 of each type of register per CPU; they are needed to perform out-of-order execution so you don’t have to wait forever for registers to become available.

Second, arithmetic is not performed with registers. Instead the contents of registers are moved to the arithmetic units, processed there, and the results are moved back to registers. Each arithmetic unit can perform all kinds of different operations. Otherwise, you would have an adder, a multiplier, a bit shifter and so on connected to every pair of registers.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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