Just give a copy of your I-797 for B to transfer your H-1B, and when it is done you need to tell A company. otherwise you may be in trouble. You can work for both of them if they both agree.