1
$\begingroup$

Recently, my demonstrator said that all instructions are eventually converted to zero-operand instructions just before they get executed. yet another demonstrator said that this "doesn't make any sense", and I don't know who to believe; none of them really gave any logical arguments.

So, I want to know is any of them right at all? I tried searching for the answer but I didn't find anything.

$\endgroup$
  • 1
    $\begingroup$ Once operands have been read (from memory or the register file) they effectively become immediates. If one does not count such as operands, the operation might be considered to have "zero operands". $\endgroup$ – Paul A. Clayton Jan 13 '19 at 21:49
1
$\begingroup$

This will depend on the computer architecture. zero-operand computer architectures use the stack, so to add 2+2:

  1. PUSH 2 (into the stack),
  2. PUSH 2 (again),
  3. ADD (call the instruction - note that no operators are passed by).
  4. POP ( 4 out of the stack)

but most other computer architectures e.g. use registers, memory addresses and values as the parameters to an instruction (in addition to the stack). For example the same 2+2 in a CISC computer.

  1. MOX AX,02 (AX=0)
  2. ADD AX,02 (AX=4)

However, if you're thinking in terms of translating a high level programming language into executable code e.g. one routine calling a subroutine the list of parameters most likely be passed by via stack and the number of parameters be reduced to 0 as in the first example.

$\endgroup$
  • $\begingroup$ I see, but the claim was that regardless of the machine type they'll always end up as zero-operand. $\endgroup$ – mhashim6 Jan 13 '19 at 20:10
  • 1
    $\begingroup$ @UpsideDownTree Your professor probably said this in a specific context or example. $\endgroup$ – Koenig Lear Jan 13 '19 at 20:14
  • $\begingroup$ Well I didn't find what she said very logical, and I asked her repeatedly about it to make sure I didn't get things wrong, and no, she insisted, claiming it was way faster to execute zero-operand instructions. $\endgroup$ – mhashim6 Jan 13 '19 at 20:18
  • 1
    $\begingroup$ If that was what she said, and there was no misunderstanding, then it is nonsense. Or she is an absolute genius and should go straight to Intel, AMD, Apple, Samsung etc. and tell them how to make their CPUs run way faster. $\endgroup$ – gnasher729 Feb 17 '19 at 0:16
1
$\begingroup$

It doesn't make sense to me at all.

Usually instructions are split into more primitive instructions more suitable for processing (sometimes instructions are combined into primitive instructions), those primitive instructions are put into a queue, together with information about their operands and results, then when all operands are available, the instruction with its operands are sent to an execution unit, and finally the result is sent to its destination.

I'd like to hear your first demonstrator explain how zero-operand instructions are supposed to work. I suspect there is some massive misunderstanding somewhere.

$\endgroup$
  • $\begingroup$ Her take on it was something along this correct-fact-yet-not-a-valid-argument "Zero-operand instructions will use the stack pointer as an accumulator". I believe I've done every possible thing to make sure there was no misunderstanding. She's a recent graduate and is not expected to be a guru in the field. Especially in this crappy education system that we do have here. $\endgroup$ – mhashim6 Jan 17 '19 at 20:43
1
$\begingroup$

I agree with everyone else who said that this makes no sense. In fact, the opposite is closer to the truth: on most medium to high end CPUs that you will use today (i.e. everything from a mobile phone up), instructions are typically converted into three-operand instructions.

For example, if the CPU presents a two-operand addition instruction to the programmer, the CPU can convert this into a three-operand instruction using register renaming. By giving different names to the source and destination register, the CPU effectively eliminates WAR hazards.

Having said that, the microarchitecture may have a slightly different idea of what an "operand" is than a programmer is used to. Even if a source operand is a register, it could be filled in with an immediate value straight away if the CPU already knows the value (i.e. it doesn't depend on any previous unexecuted instructions). The destination of an instruction may not be a "register" (either physical or architectural), but a reorder buffer (ROB) entry, which allows for speculative execution.

$\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.