It would be quite a bit easier to put that Civic engine into another Civic, but it's possible to swap it into the Mazda if you've got the time, skill, mechanical and financial resources to do it. You'll be doing a lot more custom fabricating and "fitting" of parts putting it in the Mazda, but it's not impossible to do.
It would be a pretty original car if you get it done, I'll give you that.