509 has 1024 words of program 41 bytes of data memory.on the other hand 508 has half the program memory and 25 bytes of data memory,but both micro controllers are pin compatible.If ur hex file is within the limit of 508 you can use it as 509 replacement.
The two microcontroller may have different register types or names. which you must check the datasheet. If that, the program will not work.....Or you just try it see how is the effect if do not want to read that two datasheets.
Friend, what you can do is, get a HEX disassembler to convert the HEX code back to ASM source. From there you can verify the REG names, I/O, .... etc. Than, modify the converted ASM file with correct ASM statements and Compile the ASM again to HEX for youe targeted PIC.