*Los mandatos informales
-"Escribe (tu) la tarea"
-"Compra (tu) los libros"
*Los mandatos formales
-"Haga (Usted) la tarea"
-"Compren (Ustedes) los libros"
Either way is correct.
but in mexico it usually goes before and in spain it's usually attached to the end.