Interrupt when a variable passes a threshold
If you want assignments to variables to have additional behaviors besides just overwriting th value, you have to add a little bit of abstraction. Wrap accesses to the variable with a functional interface.

E.g.

static th;

void set_th(int new_th)
{
   int old_th = th;
   th = new_th;
   if (old_th &lt;= 200 &amp;&amp; new_th &gt; 200)
   { /* enable interrupt */ }
   else if (old_th &gt; 200 &amp;&amp; new_th &lt;= 200)
   { /* disable interrupt */ }
}

int get_th(void)
{
   return th;
}


In some languages like C++, you can achieve the syntactic sugar so that actual assignment syntax to a variable triggers a function call. You write th = 42, where th is an object of class type, and the compiler actually generates th.set(42) (or that is the concept, anyway). Of course the set member function is user-defined, just like the plain C function set_th above.

You may also be able to program the machine itself to respond to the update of a memory location. That is to say, you can make the machine trigger an interrupt when a variable is updated. That can be done with a hardware watchpoint (normally used for debugging). Using a hardware watchpoint for this kind of thing is a huge hack, and could only be justified by the need to reduce the cycles to absolute minimum. I.e. you don't want to call a function to update the variable because of the overhead.