无法使用程序集更改数组的值

Cant change Values of Array using assembly

.586 ;Target processor. Use instructions for Pentium class machines
.MODEL FLAT, C ;Use the flat memory model. Use C calling conventions
.CODE ;Indicates the start of the code segment.

PUBLIC binarize
binarize PROC
push ebp
mov ebp,esp

;-------Variaveis----------
mov eax ,0; Counter
mov ebx, [ebp+8]; Limite
mov ecx, [ebp+12];ArrayChars
mov edx, [ebp+18];Tamanho
mov edi, 0
;--------------------------

LoopVer:
cmp [ecx+eax], ebx
jle elseloop
mov edi, 0
mov [ecx+eax], edi
jmp end_if
elseloop:
mov edi, 255
mov [ecx+eax], edi
end_if:
inc eax

cmp eax, edx
jne LoopVer
pop ebp
ret
binarize ENDP
END
}

行中的表达式出现语法错误 mov [ecx+eax], edi

我制作了一个 unsigned char 数组、一个 unsigned char 和一个要循环的整数。 我尝试将十六进制的 0 移动到 edi,将十六进制的 255 移动到 edi,仍然是同样的错误

Getting syntax error in expression in lines mov [ecx+eax], edi

对于具有 .586 的程序,以上指令是正确的。

更令人担忧的是您使用 sizes.

您使用 3 个参数调用 binarize 过程:一个无符号字符 (Limite),一个无符号字符数组 (ArrayChars), 和一个要循环的整数 (Tamanho).
数组由bytes组成,我们看到你用inc eax,但是你比较存储dwords。这意味着您的代码是错误的,并且在访问数组后面的 3 个字节时可能会触发分段错误。

另请注意,这可能是一个错字,第三个参数位于 [ebp+16](而不是 [ebp+18])。

我的重写如下:

  mov   dh, [ebp+8]    ; Limite
  mov   ecx, [ebp+12]  ; ArrayChars
  xor   eax, eax       ; Offset in the array

LoopVer:
  mov   dl, 0
  cmp   [ecx+eax], dh  ; DH is Limite
  jg    elseloop
  not   dl
elseloop:
  mov   [ecx+eax], dl  ; DL == {0,255}
  inc   eax
  cmp   eax, [ebp+16]  ; Tamanho
  jb    LoopVer

请记住,您正在使用 EAX 作为 从数组开始以字节为单位测量的偏移量