2013-06-23 47 views
0

我有兩個變量,我需要將值從string1移動到string2。將變量的值複製到另一個?

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

我知道如何與一個寄存器(SI)和循環,像這樣做:

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

我想知道是否有一個更短的方法。

+0

不同於論壇的網站,我們不使用的 「謝謝」,或者 「任何幫助表示讚賞」,或簽名(因此)。請參閱「[應該'嗨','謝謝',標語和致敬從帖子中刪除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be -removed-from-posts) –

回答

1

你要尋找的是REP(重複)和MOVSB(A爲* MOV * E * 小號 *特林* * YTE助記符)。

例子:

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 

參見:

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

在使用REP之前,用'CLD'清除方向標記通常是一個好主意,否則最終可能會出現一些有趣的錯誤。 – Michael

相關問題