You are on page 1of 5

String instruction

A series of data bytes or words available in memory at consecutive locations, to be


refer to collectively or individually, are called by string or word strings.

For example

A string of characters may be located in consecutive memory locations,


where each character may be represented by its ASCII equivalent.

For referring string, two parameters are required,

A) Starting or and address of the string

B) Length of string (It usually stored as count in the CX register.)

Now for the case of 8085…………..

Its similar structure may be set up by pointer or counter arrangements which


may be modified by each itration, till the required condition for proceeding further is
satisfied

And for 8086 string inst…………

It is more powerful because of its increment or decrement of pointer is


depends upon the D.F. status.

Now further,

If the string inst. is a byte string opration, the index is updated by one.

If it is a word string inst. the index registers are updated by two.

The counter in both the cases, is decremented by one.

REP: repeat instruction prefix

This instruction is prefix to any other instruction.

When it is used it executed rapidly until the CX register become zero.

When it is zero, the execution proceeds to the next instruction in sequence.

It has two types of oprations:-

1)...REPE/REPZ
For repeat instruction while equal/zero.

2)...REPNE/REPNZ

For operation while not zero.

(These options are used for CMPS, SCAS instructions only)

MOVSB/MOVSW: Move String Byte or String Word

It use for move byte which is stored in consecutive location.

The starting byte of the source string is located in memory location whose
address may be computed by SOURCE INDEX or DATA SAGMENT.

The string address of destination locations where this string has be relocated
is given by DESTINATOIN INDEX or EXTRA SEGMENT.

The starting address of the source string is

10H*DS+[SI],

While starting address of destination is 10H*DS+[SI].

The MOVSB/MOVSW instruction thus, move string word/byte pointed to by


DS:SI pair to the memory location pointed to by ES:DI pair and further work on REP.

Now from the instruction to the example….

MOV AX,5000H ;source segment address is 5000H

MOV DS, AX ; Load it to DS

MOV AX, 6000H ; Destination segment address is 6000H

MOV ES, AX ; Load it to ES

MOV CX, 0FFH ; Move length of the string to counter register CX

MOV SI, 1000H ; Source index address 1000H is moved to SI

MOV DI, 2000H ; Destination index address 2000H is moved to DI

CLD ; Clear DF, (set auto increment mode)

REP MOVSB ; Move 0FFH string bytes from source address to destination
CMPS: Compare String Byte or String Word

The CMPS inst. can be use to compare two strings of bytes or words.

The length of string must be stored in the register CX.

If both the byte or word strings are equal, zero flag is set.

The flags are affected in the same way as CMP instruction.

And more to the DS: SI and ES: DI point to the two strings and further REP inst. with
CX counter.

Now from the instruction to the example ….

MOV AX, SEG1 ; Segment address of string1, (seg1 is moved to AX)

MOV DS, AX ; Load it to DS

MOV AX, SEG2 ; Segment address of string2, (seg2 is moved to AX)

MOV ES, AX ; Load it to ES

MOV SI, OFFSET STRING1 ; Offset of STRING1 is moved to SI

MOV SI, OFFSET STRING2 ; Offset of STRING2 is moved to DI

MOV CX, 010H ; Length of STRING is moved to CX

CLD ; Clear DF, (set auto increment mode)

REPE CMPSW ; Compare 010H words of STRING1 and

; STRING2, while they are equal, if the mismatch is found,

; modify the flags and proceed with further execution

{If both the strings are completely equal i.e. CX become zero,

The ZF is set otherwise, ZF is reset}


MOV AX, SEG ; Segment address of the string, (SEG is moved to AX)

MOV ES, AX ; Load it to ES

MOV DI, OFFSET ; string offset, (offset is move to DI)

MOV CX, 010H ; Length of the string is moved to CX

MOV AX, WORD ; The word to be scanned for (WORD is in AL)

CLD ; Clear DF

REPNE SCASW ; Scan the 010H bytes of string, till a match to

; WORD is found

SPECIAL WORKING:-

This string instruction find out, if it contains WORD.

If the WORD is found in the word of string, before CX become zero, the ZF is
set, otherwise ZF is reset.

The scanning will continue till a match is found.

Once a match is found execution of a programme, proceeds’ to further.

You might also like