If the software you have is written in assembly language or you don't have the source code it will have to be completely rewritten. The instruction set is different.
If the code is written in a language like C or BASIC and you have the source code it may or may not be possible to make it work on a diffferent processor with minor changes. In this case you need a compiler for the 16F877.
The ATMEGA644 has more program memory than the 16F877, the software may not use all the memory so it might fit.
If the software just reads and controls IO pins then may be fairly easy to make it run on a different processor.
If the software uses timers, I2C, SPI,UART, internal EEPROM etc then it will be more work.
The ATMEGA644 and the 16F877 have different hardware features, for example the atmega has two UARTs but the PIC only has one.