assemblyx86x86-16

Why does adding the value 2 to the si only increment the index by 1?


I'm a beginner to the x86 architecture and assembly, this is a code snippet with the steps through below it.

I know that the si is the source index and it acts as the index to the array.

The highlighted line indicates that 2 is being added to it, however the answer suggests that we only move up an index of 1.

I'm sure I'm interpreting it wrong, if someone can explain what is happening that would help a lot!

Assembly newbie-friendly vocab preferred!

enter image description here


Solution

  • This occurs because the data in array is being treated as a different type as the indexing in si.

    Since array is declared with dw (data words, 16 bit elements) and si is a pointer which indexes memory on a byte basis (8 bits), si must take two "steps" for each word index you wish to traverse. Otherwise, you'd end up alternating between the high-order and low-order bytes of each word in the array.

    In computer-science terminology, x86 is byte addressable, and your array elements are multi-byte.