This is a typecast / overflow problem. The CODE w$(1) is of type UByte (unsigned byte).
So if you subtract CODE w$(1) - CODE w$(2) and the result is negative, it will be overflowed. In this case, -1 is 255 in Ubyte.
In the first line, the compiler guesses this in compile time, because it's constant. In the second case, it cannot, because it's computed during runtime.
You can tell the compiler the type of the expression using CAST. In this case, you want CODE w$(1) and CODE w$(2) to be of type Byte (not Ubyte), because it's signed (that is, it can be negative).
Try this:
Code:
LET w$="012": PRINT CAST(Byte, CODE(w$(1)) - CODE(w$(2))) ' gives -1