A control algorithm based on the instantaneous optimal control method is presented for on-line control of structures subjected to earthquake excitations. This algorithm employs the digital state-space equation to discretize the continuous dynamical equation of motion, and named discrete instantaneous optimal control method. Based on the Lyapunov stability method, a procedure to obtain a discrete stable weighting matrix is developed. To demonstrate the precision and the efficiency of the proposed control algorithm an 8-story shear-type building frame equipped with one active mass damper/driver (AMD) mechanism is used. Behavior of different weighting matrices is also examined.