Home  Site Map  Instruction Index 

REP  -  Repeat Instruction


The REP instruction is used to repeat repetative tasks.

It is important to set up the Source, Destination abd Counter before calling this instruction.

There are warnings that the speed may exceed the capabilities of any external devices it is writing too.

The following sample codes shows how to use REP and an alternative method using LOOP.

You should use the BYTE and WORD alternatives to these CMPS, INS, LODS, MOVS, STOS and SCAS.

This command has 2 parts, Instruction, and the task to be repeated.


Sample using
REP MOVSB
16 bit Machine
Code
MOV SI, DataString2;  Assign the Source BE 26 01
MOV DI, DataStringReturn ;  Assign the Destination BF E9 01
MOV CX, 0x0030;  Set the counter B9 30 00
REP MOVSB;  Start REP instructionF7 A4
MOV SI, DataStringReturn ;  Assign the Source B9 30 00
CALL SubPrintString;  Display the result

Sample using LOOP16 bit Machine
Code
MOV SI, DataString2;  Assign the Source BE 26 01
MOV DI, DataStringReturn ;  Assign the Destination BF E9 01
MOV CX, 0x0030;  Set the counter B9 30 00
MOVSB;  Move one byte from SI to DI A4
LOOP 0XFD;  LOOP repeats task
;  decrementing CX until CX = 0
E2 FD
MOV SI, DataStringReturn;  Assign the Source BE E9 01
CALL SubPrintString;  Display the result

REP Calls Description   16 bit Machine
  Code
REP INSB;  8 bit version inputs BYTES from Port
;  DX into DI
  F3 6C
REP INSW;  16 bit version inputs WORDS from Port
;  DX into DI
  F3 6D
REP LODSB;  8 bit version loads BYTES from SI to AL   F3 AC
REP LODSW;  16 bit version loads WORDS from SI to AX   F3 AD
REP MOVSB;  8 bit version moves BYTES from SI to DI   F3 A4
REP MOVSW;  16 bit version moves WORDS from SI to DI   F3 A5
REP OUTSB;  8 bit version outputs BYTES from SI to
;  Port DX
  F3 6E
REP OUTSW;  16 bit version outputs WORDS from SI to
;  Port DX
  F3 6F
REP STOSB;  8 bit version stores BYTES at DI   F3 AA
REP STOSW;  16 bit version stores WORDS at DI   F3 AB
REPE CMPSB;  8 bit version compares and find non-matching
;  BYTES in SI and DI
  F3 A6
REPE CMPSW;  16 bit version compares and find non-matching
;  WORDS in SI and DI
  F3 A7
REPE SCASB;  8 bit version finds a character NOT matching
;  the value of AL
  F3 AE
REPE SCASW;  16 bit version finds a character NOT matching
;  value of AX
  F3 AF
REPNE CMPSB;  8 bit version compares and finds non-matching
;  BYTES in SI and DI
  F3 A6
REPNE CMPSW;  16 bit version compares and finds non-matching
;  WORDS in SI and DI
  F3 A7
REPNE SCASB;  8 bit version finds a character that matches
;  the value of AL
  F3 AE
REPNE SCASW;  16 bit version finds a character that matches
;  the value of AX
  F3 AF