The present invention provides a method for writing data based on memory replacement, the realization process of which is as follows: setting up the memory structure, independently designing the part used for data reading and writing in the memory, and integrating two integrated circuits with exactly the same capacity ; Perform memory switching, the system starts in general mode when it is just started, and after running for a period of time, the system-related applications are completely loaded, and the memory management unit detects the capacity used by the stack according to the switching mode set by the system, and then according to The actual capacity plus a certain amount of redundancy sets the stack area, then detects the memory used for reading, and adds a certain amount of redundancy to set the read memory, and the remaining memory is completely mapped to the write memory to complete the memory switching process . Compared with the prior art, the method for writing data based on memory replacement can smooth the entire writing process by replacing the memory when writing files, improve the writing performance, have strong practicability, and be easy to popularize.