Let $X$ be a finite or infinite chain and let $\O(X)$ be the monoid of all endomorphisms of $X$.

In this paper, we describe the largest regular subsemigroup of $\O(X)$ and Green's relations on $\O(X)$.

In fact, more generally, if $Y$ is a nonempty subset of $X$ and $\O(X,Y)$ is the subsemigroup of $\O(X)$ of all elements with range contained in $Y$,

we characterize the largest regular subsemigroup of $\O(X,Y)$ and Green's relations on $\O(X,Y)$.

Moreover, for finite chains, we determine when two semigroups of the type $\O(X,Y)$ are isomorphic and calculate their ranks.