Reputation: 11
can anyone help me understanding the following instructions-
LES SI,DATA1
MOV DI,OFFSET DATA2
MOV BX,[SI]
MOV CX,[DI]
MOV[SI],CX
Upvotes: 1
Views: 1612
Reputation: 4871
LES
is not LEA
. LES x, y
interprets y
as a far pointer and loads its data into ES
(a segment register) and x
.
The instruction sequence as given is strange though, because ES
is not actually used.
Anyway, the instruction sequence (if the [SI]
are changed to ES:[SI]
) is: given a far pointer (DATA1
) and a variable (DATA2
), move the contents pointed to by DATA1
into BX
and replace them by what is stored currently at DATA2
(which will also be in CX
).
Upvotes: 3
Reputation: 1977
You can just look up an assembly instruction page, and it would explain what each of those instructions do in a simple to understand way; in many ways assembly in its basic, low-level simplicity is easier to understand a single line than in higher level languages.
I can never remember which x86 assembly syntax orders things which way if I haven't used it in a while (the two major x86 assembly syntaxes order the operands in the opposite order), so I won't say the exact result here.
For the first one, I assume that's a typo and you meant LEA instead of LES? LEA stands for "load effective address" if I recall correctly. Its main purpose it to calculate the memory address of something when you want to actually know the address instead of just use the address.
(edit) I had not used LES before, and Google wanted to redirect me to LEA, hence my above statement. I will leave the above though so you can benefit from that too. (/edit)
MOV moves data from one place to the other. The operands in the MOV instructions that are surrounded by [] square brackets mean you want that memory address instead, so MOV CX,[DI] would be "move the contents of the CX register into the memory location at the address held in the DI register" (or the other way around, [DI] into CX, see above statement about operand order).
I'm not sure on the "OFFSET DATA2" as I don't recall an offset keyword.
Upvotes: 1
Reputation: 5114
corresponds to the following C code :
// DATA1 and DATA2 are 'far' pointers to word of 16 bits, let's say they are 'short'
short bx = *DATA1;
*DATA1 = *DATA2;
// the old value of *DATA1 is still available in the BX register.
// and the value of *DATA2 is still available in the CX register.
// also, ES is set to the segment where DATA1 and DATA2 resides.
Upvotes: 0