tags:

views:

84

answers:

3

move the contents of the register bx into the register ax

MOV ax, bx

Why is the syntax so strange?

Mov ax, (to) bx actually means move contents of bx to ax ,is there any historical reason to define it this way?

+4  A: 
MOV ax, bx

This means, ax = bx (move bx to ax, more exactly, copy bx to ax). In this Assembly syntax first operand is destination - this is usual case, for example, in C functions:

strcpy(dest, source);

In AT&T Assembler first operand is source. Generally, it looks strange and AT&T Assembler users make interesting bugs because of this.

Alex Farber
+1  A: 

Excerpt from wikipedia

Syntax: x86 assembly language has two main syntax branches: Intel syntax, originally used for documentation of the x86 platform, and AT&T syntax. Intel syntax is dominant in the MS-DOS and Windows world. In the Unix/Linux world, both are used because GCC only supported AT&T-syntax in former times.

Alex
+8  A: 

Consider a code

x = 5

This probably assigns value 5 to x. Would you like 5 = x?

Similarly, You should not try to compare the language English with coding. Thats what historically also happened. English might say move this to that. But computer architects like that to this.

So basically the process of :

X := Y

could be better summarized as :

MOV X, Y
loxxy
+1 - good example.
Alex Farber
I've always felt that using the equals sign for *assignment* might be confusing for newcomers. In algebra, the expression `x = x - 5` would mean your equation is unsolvable, but it means something completely different in C. :)
Martin
@Martin: Good point Martin! +1
jyzuz
+1..There are so many things that are contradictory in programming. So I guess it is best not to compare languages on the basis of their grammers.
loxxy
Assignment in paper was traditionally `X ← Y`, and has become either `X := Y` or `X = Y` because ASCII lacks left arrows. APL uses `←`, as you can see on some of the code-golf challenges on this site.
ninjalj