lisovaccaro
lisovaccaro

Reputation: 33956

Copying a variable's value to another?

I have two variables, I need to move the values from string1 to string2.

string1 DB 20, 22 dup('?')
string2 DB 20, 22 dup('?')

I know how to do this with a register (si) and a loop, something like:

LEA si, string1
LEA di, string2
mov cx, 5
change:
mov ax, [si]
mov [di], ax
loop change

I want to know if there is a shorter method.

Upvotes: 0

Views: 86

Answers (1)

Scott Maskiel
Scott Maskiel

Reputation: 64

What you're looking for are REP (Repeat) and MOVSB (A mnemonic for *MOV*e *S*tring *B*yte).

Example:

lea     si,[string1] ;si points to string1
lea     di,[string2] ;di points to string2
mov     cx,5         ;number of bytes in string1
rep     movsb        ;copy the string

See also:

MOVSW (Move String Word - Copies 2 bytes at a time)
MOVSD (Move String DWord - Copies 4 bytees at a time)

Upvotes: 1

Related Questions