Hi yes you can sure use your AT&T sim in iphone 3g or 4 only if it is unlocked one ..Else if the iphone is locked to network other than AT&T then until you unlock it you can't freely use it with your AT&T sim .You can easily unlock your iphone with the help of providers like
WickedUnlock.com here they are rendering remote unlocking service to unlock all model iphone from network lock .You first verify that whether they are rendering service for your country and network provider .If yes then pay for it and unlock your iphone.