Sunday 25 December 2016

The 8086 String Instruction

1. MOVS:

- MOVS instruction is used for moving a string of ASCII characters from one place in the memory to the another place.

2. MOVSB:

- MOVSB instruction will perform all the actions in repeat unit loop.
- The MOVSB instruction will copy a byte from the location pointed to by the Direct Index Register.
- It will then automatically increment SI to point to the next source location.
- If you add a special prefix called the repeat prefix in front of the MOVSB instruction, the MOVSB instruction will be repeated and CX decremented until CX is counted down to zero.
- The source index register, SI must contain the offset of the start of the source string and the start of the destination location.
- Also, the number of string elements to be moved must be loaded into the CX register.
- If the direction flag is cleared with CLD instruction, then the pointers in SI and DI will automatically be incremented after each string operation. If the direction flag is set with an STD instruction, then the pointers in SI and DI will be automatically decremented after each string operation.
- It is necessary to initialize the extra segment register, for string instructions an offset in DI is added to the segment base represented by the number in the extra segment register to produce a physical address.
- If DS and ES are initialized with the same value then SI and DI will point to locations in the same segment.

3. MOVSW:

- The MOVSB instruction can be used to move a string of words depending on the state of the direction flag, SI and DI will automatically be incremented or decremented by 2 after each word move.

4. MOVSB: 

- A single MOVSB  instruction can cause the 8086 to move up to 65,536 bytes from one location in memory to another.

'$':

- A '$' is used to symbolically represent the current value of the location at any point.
- This trick with the $ sign allows you to load the number of string elements in CX symbolically, rather than having to manually count the number. This trick has the further advantage that if the password is changed and the program reassembled, the instruction that loads CX with the string length will automatically use the new value.

1 comment: