16 bit Assembly

Home   Site Map   Instruction Index  


REP   - Repeat Instruction

The REP instruction is used to repeat repetative tasks. This command has 2 parts, Instruction, and the task to be repeated.

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 CMPS, INS, LODS, MOVS, STOS and SCAS.

Sample using REP MOVSBMachine 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 LOOP
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
  Input bytes from Port DX into DI
  F3 6C
REP INSW;  16 bit version
  Input Words from Port DX into DI
  F3 6D
REP LODSB;  8 bit version
  Load bytes from SI to AL
  F3 AC
REP LODSW;  16 bit version
  Load Words from SI to AX
  F3 AD
REP MOVSB;  8 bit version
  Move bytes from SI to DI
  F3 A4
REP MOVSW;  16 bit version
  Move Words from SI to DI
  F3 A5
REP OUTSB;  8 bit version
  Output bytes from SI to Port DX
  F3 6E
REP OUTSW;  16 bit version
  Output Words from SI to Port DX
  F3 6F
REP STOSB;  8 bit version
  Store bytes at DI
  F3 AA
REP STOSW;  16 bit version
  Store Words at DI
  F3 AB
REPE CMPSB;  8 bit version
  Compare and find non-matching bytes in SI and DI
  F3 A6
REPE CMPSW;  16 bit version
  Compare and find non-matching Words in SI and DI
  F3 A7
REPE SCASB;  8 bit version
  Find character NOT matching value of AL
  F3 AE
REPE SCASW;  16 bit version
  Find character NOT matching value of AX
  F3 AF
REPNE CMPSB;  8 bit version
  Compare and find non-matching bytes in SI and DI
  F3 A6
REPNE CMPSW;  16 bit version
  Compare and find non-matching Words in SI and DI
  F3 A7
REPNE SCASB;  8 bit version
  Find character that matches value of AL
  F3 AE
REPNE SCASW;  16 bit version
  Find character that matches value of AX
  F3 AF




Last Update 06/02/2023