wow, thanks.
however in testmail should the "ram1" be "ram4"?
No. The XOR IP7 RAM4 RAM1 is detecting a "change of state".
If RAM4 was 0 and IP7 is NOW 1, then RAM1 is set to 1.
The branch instruction after that just checks if ram1 was zero or not. Ie, if there was a change of state.
If ram1 was zero, it means either:
( a ) IP1 = 1 AND RAM4 = 1
or ( b ) IP1 = 0 AND RAM4 = 0
So after the bz ram1 loop
we only get to execute more instructions if RAM4 and IP7 are different (ie, IP7 just changed state)
If IP7 just changed state, its either gone from low-to-high (leading edge), or high-to-low (trailing edge)
You only want an email notice when ip7 goes high... so if RAM4 = 0, then IP7 just went high.
In that case, we send the email. And since RAM4=0, the tsteq will also set RAM4 true.
If RAM4 *WAS* true, it won't be 0, and the test will set RAM4=false (0) and skip over the email instruction, thus achieving in one step setting or resetting the flag, and sending email only on setting the flag.