我正在尝试这个程序,但我得到错误消息说
Number1.exe中0x00411B4A处的未处理异常:0xC0000005:阅读位置0x000AFF01时发生访问冲突。
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA
array1 DWORD 0aff01h, 0bff02h, 0cff03h, 0dff04h, 0eff05h
array2 DWORD 002ff0affh, 003ff0bffh, 004ff0cffh, 005ff0dffh, 006ff0effh
array3 DWORD 5 DUP(0) ; reserve space for 5 DWORDs
count DWORD ?
.CODE
_MainProc PROC
mov ecx, 5 ; set the loop counter
lea esi, array1 ; load address of array1
lea edi, array2 ; load address of array2
lea ebx, array3 ; load address of array3
call arrMix ; call the arrMix procedure
mov eax, 0 ; set a breakpoint here
ret ; return from the program
_MainProc ENDP
arrMix PROC
mov ecx, count ; initialize loop counter
mov esi, array1 ; load address of array1
mov edi, array2 ; load address of array2
mov ebx, array3 ; load address of array3
arrMixLoop:
mov eax, {esi] ; load element from array1
and eax, 00FF00FFh ; keep only bits 0-7 and 16-23
shl eax, 8 ; shift left by 8 bits
mov edx, [edi] ; load element from array2
and edx, 0FF00FF00h ; keep only bits 8-16 and 24-31
shr edx, 8 ; shift right by 8 bits
or eax, edx ; combine the two bit sets
mov [ebx], eax ; store the result in array3
add esi, 4 ; move to the next element in array1
add edi, 4 ; move to the next element in array2
add ebx, 4 ; move to the next element in array3
loop arrMixLoop ; repeat until loop counter is zero
ret ; return from the procedure
arrMix ENDP
END ; end of source code
1条答案
按热度按时间n6lpvg4x1#
您正在调用 arrMix 过程,其中输入已经在EBX、ECX、ESI和EDI中。但是 arrMix 过程首先销毁这些输入。
从未初始化的count 变量加载ECX时,ECX=5设置会出现问题,并且3个指针会被其各自的第一个数组元素覆盖。
因为ECX很可能被0覆盖,
loop arrMixLoop
指令开始执行它的40亿次迭代!而且因为指针现在无效,读/写访问冲突必然会发生。在MASM中,
mov esi, array1
从内存中加载一个值,而mov esi, OFFSET array1
加载数组的地址(如您所料)。行
mov eax, {esi]
在开始的方括号上有一个错字。这应该是mov eax, [esi]
。