Evolvable hardware is able to offer considerably higher performance than general-purpose processors and significantly more flexibility than ASICs. In order to take the advantages of general-purpose processors and ASICs, dividing a complex process into subprocesses is essential. In this paper, we propose a evolutionary method called context switching that splits a task into a set of subtasks whose complexity is manageable on the given hardware. The method is based on genetic programming. Due to its expressive power, genetic program can represent flexible strategies for decomposing complex tasks. The effectiveness of context switching is demonstrated on the design of adaptive controllers for a team of autonomous mobile robots.