replace magic calcuation with one based on the size of the array. -1 to account for the trailing zero element, which is clearly not a real register.