-1

Definitions:

Instruction is just atomic parts of assembly language like

MOV EAX, EBX

Now let's say we have the following code written in C++ language:

int  a = 1;    
int  b = a + 3;

Here = and + are operators.

In mathematics, an operation is a function which takes zero or more input values (called operands) to a well-defined output value.


As far as I understand, we can not execute operator without assignment (basically we can write b > c; but it makes no sense), even increment and decrement work internally as x = x + 1.

So it seems to me that in computer science operation is always a result of some single operator execution. For example:

c = 1 + 2;     // this is operation since we have single + operator 
c = 1 + 2 + 3; // here we have two operations 1 + 2, and result of it + 3

Now. Not every single line of code can be translated into single instruction, for example:

int  a = 1;     // MOV EAX, 1

int  b = a + 3; // ADD EAX, 3
                // ADD EBX, EAX 

So it correct to give operation the following definition (for x86):

operation is the result of the operator execution. And it transforms into 1 or more instructions.

No Name QA
  • 724
  • 1
  • 6
  • 20
  • 2
    _operation_ is a vague word that depends on the context. And an `operator` can be invoked on its own, assignment is another `operator`. – Maxim Egorushkin Aug 19 '20 at 09:54
  • 3
    The specifications of the high-level language will **define** each term involved. "operation" is just a word, it doesn't mean anything. Even in mathematics, "operation" means nothing. Formalizing the language mathematically is hard, that's why different models were invented (PRF, TM, lambda calculus). Formalizing the semantics is a bit easier but it has nothing to do with the assembly. "instruction" is both an assembly instruction and an HL statement, depending on the context. You are looking for a connection that doesn't exist :) Just read the C standard and you'll understand. – Margaret Bloom Aug 19 '20 at 10:06
  • You are talking about three different languages, different contexts, you can choose how to use a word like that per context, there is no connection between them. You need to not get so worked up about individual terms, language in general is not specific like this, and trying to make it that way will lead to confusion and failure. – old_timer Aug 19 '20 at 11:56
  • Stay within the bounds of you and the individual you are talking to as far as terminology and definitions goes, both sides tune during the conversation. Some other individual can/will have a completely different set of terms or definitions for the same term and you simply adapt for that conversation, repeat. You can look at any dictionary, esp the OED, to see that terms have different meanings as well as changing over time, sometimes to mean something completely different. – old_timer Aug 19 '20 at 11:59
  • within the processor an instruction is as defined in the documentation. add, mov, etc. are instructions. that term does not make sense in C, and an assembly language instruction is not always one to one with a machine code instruction so you have to again rely on context and not assume some global definition. – old_timer Aug 19 '20 at 12:47
  • `int b = a + 3;` takes 1 MOV and one ADD, or one LEA. Your implementation would make the new value of `b` depend on the old value of EBX, not just on `EAX + 3`. Also, it would modify `a` because you added to EAX instead of copying and *then* modifying the copy. – Peter Cordes Aug 19 '20 at 20:50

1 Answers1

4

Here’s my understanding: Instruction is the lower level term for telling you what to do in each step, concerning registers, memory addresses etc. So an operation we write in the language can take multiple instructions in the lower level language.

A function can have multiple operators.
An operation can take multiple instructions to implement.
(Or sometimes, a single asm instruction can implement multiple operations, like an x86 lea eax, [ecx + edx*4 + 123] implementing x + (y<<2) + 123)

The greater than symbol is also an operator: it compares the LHS value with the RHS value. And there are unary operators as well: (++) (!) etc.

Operators with compile-time-constant operands like 1+2+3 can be evaluated to a single constant at compile time, taking no asm instructions. (Or 1 mov if you can't just use that constant later as an immediate)

And operators need not be mathematical: in C++, delete and new are also operators in terms of C++ syntax rules. But in asm they're implemented as function calls.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
srv236
  • 509
  • 3
  • 5