Search code examples
x86masm

Moving a register into an index of an array in x86 assembly language


I'm trying to move the bl register into an array of bytes in x86 assembly language, but the following statement produces an error message from the masm assembler.

mov arr[2], bl produces the output 1>p4.asm(48): error A2101: cannot add two relocatable labels.

Is it possible to move a register into an array in x86 assembly language?


Solution

  • Basically something that the following should work for a hard coded index value:

    mov byte ptr [arr + 2], bl  ;store bl
    

    The [] are optional: Confusing brackets in MASM32

    For a more generic way:

    mov si, 2                ;your index
    mov al, bl               ;bl = byte value from your question
    mov bx, offset arr
    mov byte ptr [bx+si], al