This question may be utterly trivial, or not, but as someone with hardly any knowledge of algebraic geometry I thought there could be a chance I get lucky.

Let X be a rational surface obtained by n blows up of $\mathbb{P}^1(\mathbb{C})\times\mathbb{P}^1(\mathbb{C})$. I write $H_x$ and $H_y$ for the lines x=constant and y=constant, and $E_i$ for the total transform of the point of the $i-th$ blow up. Is there some way to find what the canonical divisor on X is? Take for example the surface X blown up at the point $x=\infty$ , $y=\infty$, and then again on that divisor at some point.

(This example above occured when I cooked up an example to try and understand the resolution of singularities for the simple mapping x(n+2)+ax(n+1)+bx(n)=0).

I have seen for example, that the canonical divisor of $\mathbb{P}^2(\mathbb{C})$ blown up at 9 points is given by $K_X=-3H+E_1+E_2+...+E_9$. Is this true in general or only for a special class of surfaces?