calculate relative addresses for corner cases (mem looping)