BYTE数组逆序存入DWORD
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
INCLUDE Irvine32.inc
.data
bigEndian BYTE 12h,34h,56h,78h
littleEndian DWORD ?
.code
main proc
;dump bigEndian
mov esi, OFFSET bigEndian
mov ecx, LENGTHOF bigEndian
mov ebx, TYPE bigEndian
call DumpMem
;eax = 0, loop for eax<<4 and eax=eax+bigEndian[i-1], i = from lenth(bigEndian)-1 to 0
mov eax, 0
mov ecx, LENGTHOF bigEndian
L0:
shl eax, 8
add al, bigEndian[ecx - 1]
loop L0
;littleEndian = eax
mov littleEndian, eax
;dump littleEndian
mov esi, OFFSET littleEndian
mov ecx, LENGTHOF littleEndian
mov ebx, TYPE littleEndian
call DumpMem
invoke ExitProcess,0
main endp
end main
WORD数组存入DWORD数组
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
INCLUDE Irvine32.inc
.data
array1 WORD 10h,20h,30h,40h
array2 DWORD LENGTHOF array1 DUP(?)
.code
main proc
mov ecx, LENGTHOF array1
mov edi, 0
mov esi, 0
;clear eax
mov eax, 0
L0:
;mov array1[index] to eax and copy to array2[index]
mov ax, array1[edi]
mov array2[esi], eax
;array1 index + 2
add edi, 2
;array2 index + 4
add esi, 4
loop L0
;dump array1
mov esi, OFFSET array1
mov ecx, LENGTHOF array1
mov ebx, TYPE array1
call DumpMem
;dump array2
mov esi, OFFSET array2
mov ecx, LENGTHOF array2
mov ebx, TYPE array2
call DumpMem
invoke ExitProcess,0
main endp
end main
字符串逆序存储
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
INCLUDE Irvine32.inc
.data
source BYTE "This is the source string",0
target BYTE SIZEOF source DUP('#')
.code
main proc
;size of source, sub tail 0
mov ecx,SIZEOF source - 1
;address index esi
mov esi,0
L0:
;mov source[ecx - 1] to target[esi]
mov al,source[ecx - 1]
mov target[esi],al
inc esi
loop L0
;add 0 to target
mov target[esi],0
;display target
mov edx,OFFSET target
call WriteString
invoke ExitProcess,0
main endp
end main
数组循环右移一位
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
INCLUDE Irvine32.inc
.data
array DWORD 10h,20h,30h,40h
.code
main proc
;dump array
mov esi, OFFSET array
mov ecx, LENGTHOF array
mov ebx, TYPE array
call DumpMem
;length for loop
mov ecx, LENGTHOF array - 1
;store array[tail]
mov edi, ecx
shl edi, 2
mov eax, array[edi]
;loop for array[index]=array[index - 1]
L0:
mov ebx, array[edi - 4]
mov array[edi], ebx
sub edi, 4
loop L0
;array[0]=tail
mov array[edi], eax
;dump array
mov esi, OFFSET array
mov ecx, LENGTHOF array
mov ebx, TYPE array
call DumpMem
invoke ExitProcess,0
main endp
end main