All the information required on how to access external memories and hence logic are in the PDF file for the AT89S51. The code itself is going to be completly dependant on the timeing charactoristics of your external interface which you have supplied no information on.