Is it possible to change the engine between a 1990 525i and a 1990 325i?

The 1990 325i has a M20B25 motor. The earlier 1990 525i had the same motor, a M20B25, whereas the later 1990 525i had a M50B25.