是的, If you file 539 before your last pay day (a couple of weeks after is fine in most time), your status 就不是非法. You can file a H-1B transfer based on pending application. CIS allows a gap of up to two months in H1 for a H-1B transfer if gap is filled with a legal status (such F1 pending, B2 pending). This stragegy will offer you benefit even in the worst scenerio, where your case is handled by a picky officer and he denied your F1 or B2 application first and then denied your H-1 transfer, you become out-of status only after your F1 or B2 application is denied.
In most case, officer will approve your H-1B tranfer first and then do you a favor by dening your F1 or B2 application.