fix left shift bug that happens if p >= sp
be explicit about order of operations