交换字符串的第一个和第二个字符

时间:2018-02-22 18:49:55

标签: assembly x86 swap masm irvine32

我想换掉2个角色和第1个角色。我的代码是:

INCLUDE Irvine32.inc

.data
array byte "scs212",0

.code
main proc

mov esi,array 
mov al,[esi]
inc esi 
move bl,[esi]
xchg al,bl 
dec esi 
move [esi],al
inc esi
move [esi],bl

mov edx, offset array
call WriteString
exit 
main ENDP
END main

我这样尝试但没有工作 result = css212

1 个答案:

答案 0 :(得分:0)

MOV  ESI,offset array   ;pointer to first position
MOV  AL,[ESI]
INC  ESI 
MOV  BL,[ESI]
XCHG AL,BL 
DEC  ESI 
MOV  [ESI],AL
INC  ESI
MOV  [ESI],BL
INC  ESI