the rule is simple ;
you should
enter and exit a common travel area - Schengen Zone in this case -
with the
same passport , so that the entry/exit stamp should be on ONE passport.
(failure to do so would result in a stamp missing | entry stamp missing meaning entering illegaly , exit stamp missing meaning overstaying | altough these procedures are rarely checked in spain / italy / france and enforced in Switzerland / germany / netherlands...)
oh and if you want to exit schengen area fom spain i strongly recommend the neighboring morocco either with ferry if you're in southern spain or trought low cost
airfares (60€ roundtrip Ryanair) trought Madrid - Marrakesh
hope that helps