for
loop. Array a
is locally defined, and array b
is globally defined. These definitions will impact the assembly code.00401006 mov [ebp+var_18], 0 0040100D jmp short loc_401018 0040100F loc_40100F: 0040100F mov eax, [ebp+var_18] 00401012 add eax, 1 00401015 mov [ebp+var_18], eax 00401018 loc_401018: 00401018 cmp [ebp+var_18], 5 0040101C jge short loc_401037 0040101E mov ecx, [ebp+var_18] 00401021 mov edx, [ebp+var_18] 00401024 mov [ebp+ecx*4+var_14], edx ❶ 00401028 mov eax, [ebp+var_18] 0040102B mov ecx, [ebp+var_18] 0040102E mov dword_40A000[ecx*4], eax ❷ 00401035 jmp short loc_40100F
In this listing, the base address of array b
corresponds to dword_40A000
, and the base address of array a
corresponds to var_14
. Since these are both arrays of integers, each element is of size 4, although the instructions at ❶ and ❷ differ for accessing the two arrays. In both cases, ecx
is used as the index, which is multiplied by 4 to account for the size of the elements. The resulting value is added to the base address of the array to access the proper array element.