Recall that the total differential for the internal energy of a thermodynamic system is given by:
dE = TdS - PdV
Rearranging this to solve for dS, we get:
dS = (1/T)(dE + PdV)
Also recall that the amount of work done to expand a gas by an infinitessimal volume (dV) is given by:
dw = -PextdV
From the first law of thermodynamics that dE = dw + dq
Combining this with our previous expression, we see that:
dE = dq - PextdV
or
dq = dE + PextdV
Now, here is the crucial answer to your question. For a reversible process, Pext = P and dwrev = -PdV
Therefore, we now see that dE + PdV = dqrev and therefore dS = dqrev/T.