Move register value into an array

2019-09-05 08:24发布

I'm working on this assembly problem where I'm looping through each element in array1 and storing the index of that array where the entry is "F".

I'm using MASM for x86 intel processors. Assembly Language

INCLUDE Irvine32.inc
.data
array1 BYTE "FMMFMFMMFFMMFFFMFMFM",0
indexa1 BYTE SIZEOF array1 DUP(?)
ArraySize = ($ - array1)

.code
main PROC

mov esi,0          ; index
mov ecx,ArraySize

L1: cmp esi,ecx            ; check to continue loop
    jl  L2                 ; continue
    jmp L5                 ; exit

L2: cmp array1[esi], "F" ; Check if "F"
    je L3                ; jump if "F"
    jmp L4               ; jump to L4 if not "F"

L3: 
   mov indexa1[ah], esi   ; store index number,---- ERROR ----
   inc ah
   jmp L4

L4: inc esi ; increment loop counter
    jmp L1  ; jump to beginning

L5: movzx eax, ah
    call DumpRegs

exit    
main ENDP
END main

Why do I get an error trying to store the index in indexa1? Error says, must be index or base register

1条回答
Evening l夕情丶
2楼-- · 2019-09-05 09:03

indexa1[ah] doesn't match any valid addressing mode on the x86. Use a 32-bit register (e.g. eax) as the counter instead.

See figure 3-11 in Intel's Software Developer's Manual.

查看更多
登录 后发表回答