This question comes up occasionally. 612 to 647 and the reverse. It is complicated but if you have a complete donor engine vehicle w/ECM, wiring harnesses, IC, SKREEM, same rear axle ratios, etc. it might be possible but you get the picture.
Are you in the USA? Email me regarding repairing your '04 engine. Doktor A