Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About mov in assembly

Tags:

assembly

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?

like image 472
COMer Avatar asked Dec 01 '22 04:12

COMer


2 Answers

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
like image 108
loxxy Avatar answered Dec 05 '22 05:12

loxxy


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.

like image 34
Alex F Avatar answered Dec 05 '22 06:12

Alex F