Lesson 4. Data Operation Instructions.
Prev || Home || Next
They are used to move the contents of the operators. Each
instruction can be
used with different modes of directioning.
MOVS (MOVSB) (MOVSW)
These are specific register instructions. They are used to load bytes or chains
of bytes onto a register.
LODS (LODSB) (LODSW)
These instructions allow the use of the STACK to store or retrieve data.
Purpose: Data transfer between memory cells, registers and the accumulator.
MOV Destination , Source
Where Destiny is the place where the data will be moved and Source is the place where the data is.
The different movements of data allowed for this instruction are:
*Destiny: memory. Source: accumulator
*Destiny: accumulator. Source: memory
*Destiny: segment register. Source: memory/register
*Destiny: memory/register. Source: segment register
*Destiny: register. Source: register
*Destiny: register. Source: memory
*Destiny: memory. Source: register
*Destiny: register. Source: immediate data
*Destiny: memory. Source: immediate data
This small program moves the value of 0006H to the AX register, then it moves the content of AX (0006h) to the BX register, and
lastly it moves the 4C00h value to the AX register to end the execution with the 4C option of the 21h interruption.
MOVS (MOVSB) (MOVSW) Instruction
Purpose: To move byte or word chains from the source, directed by SI, to the destiny directed by DI.
This command does not need parameters since it takes as source address the
content of the SI register and as destination the content of DI. The following
sequence of instructions illustrates this:
MOV SI, OFFSET VAR1
MOV DI, OFFSET VAR2
First we initialize the values of SI and DI with the addresses of the VAR1 and
VAR2 variables respectively, then after executing MOVS the content of VAR1 is copied onto VAR2.
The MOVSB and MOVSW are used in the same way as MOVS, the first one moves one byte and the second one moves a word.
LODS (LODSB) (LODSW) INSTRUCTION
Purpose: To load chains of a byte or a word into the accumulator.
This instruction takes the chain found on the address specified by SI, loads it
to the AL (or AX) register and adds or subtracts , depending on the state of DF,
to SI if it is a bytes transfer or if it is a words transfer.
MOV SI, OFFSET VAR1
The first line loads the VAR1 address on SI and the second line takes the
content of that locality to the AL register.
The LODSB and LODSW commands are used in the same way, the first one loads a byte and the second one a word (it uses the complete
Purpose: It transfers the content of the flags to the AH register.
This instruction is useful to verify the state of the flags during the execution
of our program.
The flags are left in the following order inside the register:
SF ZF ?? AF ?? PF ?? CF
The "??" means that there will be an undefined value in those bits.
Purpose: To load the register of the data segment
LDS destination , source
The source operator must be a double word in memory. The word associated with the largest address is transferred to DS, in other
words it is taken as the
segment address. The word associated with the smaller address is the
displacement address and it is deposited in the register indicated as destiny.
Purpose: To load the address of the source operator
LEA destination , source
The source operator must be located in memory, and its displacement is placed on the index register or specified pointer in
To illustrate one of the facilities we have with this command let us write an
MOV SI,OFFSET VAR1
Is equivalent to:
It is very probable that for the programmer it is much easier to create extense
programs by using this last format.
Purpose: To load the register of the extra segment
LES destination , source
The source operator must be a double word operator in memory. The content of the word with the larger address is interpreted
as the segment address and it is placed in ES. The word with the smaller address is the displacement address and it is placed
in the specified register on the destiny parameter.
Purpose: It recovers a piece of information from the stack
This instruction transfers the last value stored on the stack to the destiny
operator, it then increases by 2 the SP register.
This increase is due to the fact that the stack grows from the highest memory
segment address to the lowest, and the stack only works with words, 2 bytes, so then by increasing by two the SP register, in
reality two are being subtracted from the real size of the stack.
Purpose: It extracts the flags stored on the stack
This command transfers bits of the word stored on the higher part of the stack
to the flag register.
The way of transference is as follows:
These localities are the same for the PUSHF command.
Once the transference is done the SP register is increased by 2, diminishing the
size of the stack.
Purpose: It places a word on the stack.
The PUSH instruction decreases by two the value of SP and then it transfers the
content of the source operator to the new resulting address on the recently
The decrease on the address is due to the fact that when adding values to the stack, this one grows from the greater to the
smaller segment address, therefore by subtracting 2 from the SP register what we do is to increase the size of the stack by two
bytes, which is the only quantity of information the stack can handle on each input and output of information.
Purpose: It places the value of the flags on the stack.
This command decreases by 2 the value of the SP register and then the content of the flag register is transferred to the stack,
on the address indicated by SP.
The flags are left stored in memory on the same bits indicated on the POPF
Prev || Home || Next