使用 XCHG 指令将整数重新排序为 10-8-6-4-2 x86 程序集

Use the XCHG instruction to reorder the integers to 10-8-6-4-2 x86 assembly

我正在尝试使用 xchg 指令在双字数组中交换元素 1 与元素 5 和元素 2 与元素 4。我只是寻求指导以帮助我入门。到目前为止我有这个。我正在尝试将这些指令用于双字数组。

mov ax,val1
xchg 斧头,val2
mov val1,ax

.data
myArray BYTE 2,4,6,8,10
DArray DWORD 5 DUP(?)
.code
main PROC
mov esi, OFFSET myArray
mov edi, OFFSET DArray
mov ecx, 5

L1:  movzx eax, byte ptr [esi]
mov [edi], eax
inc esi
add edi, 4
call WriteDec
loop L1
mov al, byte ptr [esi]
xchg al, byte ptr [esi]+4
mov byte ptr[esi], al
call WriteDec
mov ah, byte ptr [esi]+1
xchg ah, byte ptr [esi]+3
mov byte ptr [esi]+1, ah
call WriteDec

字节数组中的交换缺少ESI寄存器的设置。

mov esi, OFFSET myArray     <<< Add this
mov al, byte ptr [esi]
xchg al, byte ptr [esi]+4
mov byte ptr[esi], al
call WriteDec               <<< Is this useful ???
mov ah, byte ptr [esi]+1
xchg ah, byte ptr [esi]+3
mov byte ptr [esi]+1, ah
call WriteDec               <<< Is this useful ???

I'm trying to swap element 1 with element 5 and element 2 with element 4, in the dword array using xchg instruction.

mov  edi, OFFSET DArray
mov  eax, dword ptr [edi]
xchg eax, dword ptr [edi]+16
mov  dword ptr[edi], eax
mov  eax, dword ptr [edi]+4
xchg eax, dword ptr [edi]+12
mov  dword ptr [edi]+4, eax