Boot code is at a specific location on any hard disk so the scripts check the locations.
How does it moves the code to an other area of the hard disk?
Not sure what you mean here? Grub doesn't move the windows code, it locates it and chainloads it so the windows bootloader can boot the system. Someone else with a little more knowledge will probably come along and give you more details.