Reputation: 1023
I'm an ASM beginner, I know that the mul instruction just works with a register or a memory.
Now, when we use : mul var1
, how the value of var1 is retrieved? I think it should go through a register first, right? But in this case, what happens in case all registers are occupied?
Upvotes: 0
Views: 585
Reputation: 11428
The x86 architecture does not impose that every aritmetic/logic instruction has to have its operands in registers. In fact, both operands can be registers, one to be a register and another one the effective address of a matching size operand in memory, or an inmediate value.
So, when a MUL instruction, other than one that multiplies two registers, is executed, it just takes its operands from wherever they are, put them in internal (not available for the programmer) registers, and perform the operation.
The exact procedure differs a lot with every evolution of the x86 architecture. Some CPU's do a register renaming: they have plenty of internal registers, and assign them dinamically to operands of instructions just dispatched for execution. Others use what they call "reservation stations" (Tomasulo's algorithm), in which the operands are stored waiting for a functional unit to be available.
Upvotes: 1
Reputation: 700342
The named registers are for holding values between instructions, the ALU has internal registers where the values are held until the operation can be performed on them.
A value doesn't have to go from memory to a register and then to the ALU, it can go directly from memory to the ALU.
Upvotes: 2