Ah the infamous XS500 engine. If you get one, make sure it is from the last years of production in 1976 to 1978. The early engine known as TX500 from 1973 and '74 were pretty bad engines. It had what Yamaha called Omni Phase Balancer to make the engine smooth, but what happened is the balancer, in time, would actually go out of balance and hammer the engine instead. The engine also had overheating problems and the four valve head would commonly crack between the valves. The TX500 series was an embarrassment for Yamaha and caused recalls. By the way, the TX750 was even worse, but that's another story. The later model XS was an improvement but it's miserable history was too much to overcome and the model never sold well. Yamaha was determined to get it right and replaced the XS500 mid range line with our XS360 in 1976 and bumped up to 400cc later. The XS360/400 has a reputation as a very good motor. Yamaha was sure to get it right this time.
OK getting to your question about mounting one in our frame, the first thing I think of is the top engine mount that attaches to the 400 head cover. The 500 does not use that mount so it would likely have to be cut off to make room. The three mounts the 500 uses are roughly the same as your '81 but you will likely have to fabricate new mounting plates. Keep in mind the 1981 and '82 400 Specials don't use the top rear mount, so non is fitted to the frame.