Search code examples
assemblycompiler-construction

What makes x = 2 machine independent vs MOV X , 2?


From Compiler Construction (Louden):

Assembly language is extremely dependent on the particular machine for which it was written, so code written for one computer must be completely rewritten for another machine. Clearly, the next major step in programming technology was to write the operations of a program in a concise form more nearly resembling mathematical notation or natural language, in a way that was independent of any one particular machine and yet capable of itself being translated by a program into executable code. For example, the assembly code MOV X, 2 can be written in a concise, machine-independent form as x = 2

I don't understand—I guess I'm missing his point. If modern programming languages used MOV X, 2 instead of x = 2, how would that make them any less machine-independent? A compiler would still have to translate either statement into a machine code equivalent, wouldn't it?


Solution

  • The example MOV X, 2 assumes that MOV is a hardwired CPU instruction. It loads 2 into register X. You are right that a parser could translate MOV X, 2 into any other language. In fact, the assembler does parse and translate it into machine language, which is just a stream of 0 and 1.

    x=2 on the other hand side does not resemble machine instructions. It is a typical syntax found in higher level languages.