I know that the Arithmetic Logic Unit (ALU of a processor performs arithmetic (and bitwise) operations and the result is stored as the ALU's output - but what component, device or software is actually accessing/using the output of an ALU? And is it valid to say that the ALU returns the result of an operations or would that be wrong?
-
Possible duplicate of [How Do Computers Work?](https://softwareengineering.stackexchange.com/questions/81624/how-do-computers-work) – gnat Feb 12 '18 at 05:13
1 Answers
It depends heavily on the processor design; however, broadly I'd say that, the ALU output from a requested operation is temporarily available, and depending on the instruction being executed:
- the ALU output is captured to the accumulator, or
- to a particular register, or
- even sent to the data bus (e.g. for a memory write operation), or
- sent back to the ALU as input for another operation, or,
- simply ignored!
Regarding the last, not all instructions make a request of the ALU — consider a branch instruction, perhaps, that has its own way of computing the new pc value not involving the ALU. However, even when not in use, the ALU is still there and still has output lines, just that the capture/forwarding mechanism is configured to do nothing with the output.
Yes, so let's talk about a machine instruction that does ADD r3,r1,r2
where r1
& r2
are sources from the register file and r3
is a target in the register file.
Register r3
will (at the one proper cycle when the ALU result is know to be read) be switched into a capture mode and the ALU output will be made available to the register file data lines. By the next clock, the ALU output will have been captured into r3
.
If the instruction had been "LOAD r3, ..." then the same capture enable would happen but the data bus value would be made available to the register file data lines instead of the ALU.
Later if a STORE r3,...
is executed, the value in r3
will be placed onto the data bus for the memory write.
The register file is "ported". It can have multiple read and/or write ports. Each port allows access to the register file in the same cycle. So, two read ports and one write port would mean that two different registers can be read in the same cycle and that one can be written in that same cycle.

- 33,282
- 5
- 57
- 91
-
Thank you. So let's say that I have the code `int x = x+y;` - so ALU would do some arithmetic operations and how would the output then be stored in memory? I mean, something must be accessing the output of the ALU and then somehow move it forward to somewhere else – Ukula Udan Feb 11 '18 at 23:32
-
Wow - what a perfect answer. But when the output is sent to the data bus, will the result of the operation performed in the ALU be stored in the ALU itself (and the be taken directly from there to the data bus) or will it first be stored in some register and then sent to the data bus? – Ukula Udan Feb 11 '18 at 23:47
-
No, the ALU typically just does computation and if something doesn't capture the result, it is lost. However, the data bus may function like a register (in being able to hold a value for multiple cycles, and/or until it is overwritten) especially if data operations may take several cycles. (depending on processor...) – Erik Eidt Feb 11 '18 at 23:53
-
So it is the last option, right? That the output of the operation will be stored in some register and THEN sent to a data bus from there? Oh, just saw you added extra details - I'll try to read that now – Ukula Udan Feb 11 '18 at 23:55
-
Alright - but in the cast that the data bus does not function like a register - the output of the operation performed by the ALU will be stored in some register and THEN sent to a data bus from there, right? – Ukula Udan Feb 11 '18 at 23:57
-
Yes, the output would be stored in a register if it were needed for multiple cycles (e.g. to accomplish a write to memory). The ALU typically does not remember (output) values from one cycle to the next. (However, on certain processors the ALU output can be fed directly back into the ALU input for another ALU operation, which almost accomplishes the idea of memory across cycles.) – Erik Eidt Feb 11 '18 at 23:58
-
1Fundamentally, you are asking about stateful vs. stateless hardware circuits. The ALU might be considered stateless, whereas registers are stateful. Search, for example, "difference between sequential and combinational logic". Fundamentally, a register that can remember across cycles has a feedback loop of some sort that causes it to remember the same value from cycle to cycle unless set to capture a new value, and this is considered stateful circuitry; whereas combinational logic is functional in producing the same output given the same inputs, and this is considered stateless circuitry. – Erik Eidt Feb 12 '18 at 00:02
-
Ahh okay. So let me get this straight: The ALU does not remember/store its output/the results of the operations performed - they are just directly sent to somewhere else (like the registers or directly to the data bus, or one of the other possibilities you wrote) in which the value will be stored/remembered and i.e. the ALU is stateless and registers (not sure about the data bus) are stateful? Is that correct? Please correct me if I am wrong. – Ukula Udan Feb 12 '18 at 00:12
-
-
Perfect, perfect. perfect, I could not have asked for more. You were a great help!! – Ukula Udan Feb 12 '18 at 10:51
-
Oh I just noticed that I forgot to ask you about how you would define a "register file". Of course, I have tried to look it up, but the definition is not really clear, at least not to me. And based on how you have helped me before, I think you would be the perfect person to ask. – Ukula Udan Feb 12 '18 at 23:13
-
A register file the implementation of the instruction-set-specific registers, and it is an array of registers that the hardware can index during decode and execution of source & target operands in instructions. Note that though the hardware can dynamically index into the register file as an array, the software running on the processor can only dynamically index memory like an array; otherwise software can access registers only as individuals (like variables not like an array). – Erik Eidt Feb 12 '18 at 23:35
-
@asd Side note: If you want to experiment, you can build all these parts in a simulator like Logisim, and see what is and isn't possible, and how you can make stuff work. – user253751 Feb 13 '18 at 00:16
-
I knew it! You were the perfect one to ask. Thanks. And @immibis thank you, i'll take a look at that – Ukula Udan Feb 13 '18 at 09:52