Moral behavior is any behavior that causes human groups to work together more easily.
Example:
Stealing causes distrust and enmity between animals who participate in it. If all animals in a group were to agree simply to not steal from each other, then they no longer have to watch each other quite so closely. They can save themselves the effort of protecting their possessions from each other quite so hard. They can, through this common agreement, allow themselves and others more liberty within the community. This allows them to work toward common goals more easily which gives them a solid advantage as a group over less organized animals. It doesn't matter whether they use cold logic to arrive at this conclusion or fool themselves with notions of honor and "moral ethic", the function of such behavior is clearly to provide a competitive advantage over other species. In that sense it is, in some degree, inevitably a part of the makeup of any social animal.
That's the ideal situation. We all know that humans do indeed steal from each other from time to time. That occurs in instances where circumstance or opportunity temporarily cause the advantage of an immoral act to outweight the disadvantage of breaking the moral code. The individual then commits an act that, if discovered, would have some great or small negative impact on the unity of the society as a whole if it is discovered. A race of machines might always have the greater good at the fore of their minds, but a human animal is also looking out for itself at all times.
Most people won't even think of the actual overarching purpose of morality, but rather think of it in terms of honor and sacrifice and respect. All of those things are part of it, but honor, sacrifice, and respect have reasons for existence as well. They are all the tools that nature uses to make an animal "moral", that is to say, to make an animal able to work together with it's peers. Morality is not some god-given gift, but an essential necessity for us to be what we are. We had to evolve it, both culturally and instinctually in order to compete with the rest of the world.