From 26 CFR 1.1012(c)(1)i):
... if a taxpayer sells or transfers shares of stock in a corporation that the taxpayer purchased or acquired on different dates or at different prices and the taxpayer does not adequately identify the lot from which the stock is sold or transferred, the stock sold or transferred is charged against the earliest lot the taxpayer purchased or acquired to determine the basis and holding period of the stock.
From 26 CFR 1.1012(c)(3):
(i) Where the stock is left in the custody of a broker or other agent, an adequate identification is made if—
(a) At the time of the sale or transfer, the taxpayer specifies to such broker or other agent having custody of the stock the particular stock to be sold or transferred, and ...
So if you don't specify, the first share bought (for $100) is the one sold, and you have a capital gain of $800. But you can specify to the broker if you would rather sell the stock bought later (and thus have a lower gain). This can either be done for the individual sale (no later than the settlement date of the trade), or via standing order:
26 CFR 1.1012(c)(8)
... A standing order or instruction for the specific identification of stock is treated as an adequate identification made at the time of sale, transfer, delivery, or distribution.