Short on time but this might get you started

Rewrite this
R2=10.000/[(5000/ad_res)-1]
to look like this
R2=10.000*ad_res/[5000-ad_res]

calculate the denominator and keep (5000 - ad_res)
Calculate the numerator (10.000*ad_res)
Use Div32 to divide the numerator by the denominator

Use Darrel's method to get the remainder

http://www.picbasic.co.uk/forum/showthread.php?t=1942