0
What is REP prefix? How it functions for string instructions?

Mumbai University > Electronics and Telecommunication > Sem 4 > Microprocessor and peripherals

Marks: 5M

Year: May 2014, Dec 2014

0
0

Mnemonic: REP

Operation:

  • This is an instruction prefix which can be used in string instructions.
  • It can be used with string instructions only.
  • It causes the instruction to be repeated CX number of times.
  • After each execution, the SI and DI registers are incremented/decremented based on the DF (Direction Flag) in the flag register and CX is decremented i.e. DF = 1; SI, DI decrements.
  • Thus, it is important that before we use the REP instruction prefix the following steps must be carried out.

    • CX must be initialized to the count value. If auto decrementing is required, DF must be set using STD instruction else cleared using CLD instruction.

    E.g. MOV CX, 0023H

    CLD

    REP MOVSB

    The above section of a program will cause the following string operation

    ES: [DI] ← DS: [SI]

    SI ← SI + I

    DI ← DI + I

    CX ← CX – 1

    to be executed 23H times (as CX = 23H) in auto incrementing mode (as DF is cleared).

REPZ/REPE (Repeat while zero/Repeat while equal)

  • It is a conditional repeat instruction prefix.
  • It behaves the same as a REP instruction provided the Zero Flag is set (i.e. ZF = 1).
  • It is used with CMPS instruction.

REPNZ/REPNE (Repeat while not zero/Repeat while not equal)

  • It is a conditional repeat instruction prefix.
  • It behaves the same as a REP instruction provided the Zero Flag is reset (i.e. ZF = 0).
  • It is used with SCAS instruction.
0
Please log in to add an answer.

Continue reading

Find answer to specific questions by searching them here. It's the best way to discover useful content.

Find more