For a MASM-style assembler, your use of OFFSET is fine, but
- The loop forgets to advance the pointer to the next array element! Perhaps
add ecx, 1 was meant to be add esi, 1?
- The
add ebx, [esi] instruction will add a whole dword to EBX.
Because myArray comprised bytes, you need to extend the values
Both errors explain why the dump shows EBX = 00090603 in the end (00030201h + 00030201h + 00030201h = 00090603h).
xor eax, eax ; Sum
mov ecx, 3
mov esi, OFFSET myArray
More:
movzx edx, byte ptr [esi]
inc esi ; Move to next byte
add eax, edx ; Sum += Item
dec ecx
jnz More
Since in the end you want the result in EAX anyway, then also add to EAX instead of to EBX in the loop.
Data directives db, dw, dd
When you define an array of bytes using the db directive as in myArray db 1, 2, 3 the memory at the address myArray will show next 3 bytes:
1, 2, 3
To fetch a single array element and have it stored in a 32-bit register you would use movzx edx, byte ptr [esi] which is an instruction that reads 1 byte from memory, extends the byte into a dword padded with zeroes on the left1, and then leaves the result in the 32-bit register.
When you define an array of words using the dw directive as in myArray dw 1, 2, 3 the memory at the address myArray will show next 6 bytes:
1, 0, 2, 0, 3, 0
To fetch a single array element and have it stored in a 32-bit register you would use movzx edx, word ptr [esi] which is an instruction that reads 2 bytes (aka word) from memory, extends the word into a dword padded with zeroes on the left1, and then leaves the result in the 32-bit register.
When you define an array of dwords using the dd directive as in myArray dd 1, 2, 3 the memory at the address myArray will show next 12 bytes:
1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0
To fetch a single array element and have it stored in a 32-bit register you would use mov edx, [esi] which is an instruction that reads 4 bytes (aka dword) from memory, and then leaves the result in the 32-bit register.
1 Although in the register the zeroes are padded on the left, in memory the zeroes are padded on the right since x86 is a little-endian architecture. The low byte(s) come(s) before the high byte(s) when seen in memory.
EDX = 00000001h myArray : 1, 0, 0, 0