1 out of 1 members found this post helpful.
Did you find this post helpful?

|
Re: How to detect variable going below zero, without using PBPL ?
As long as both variables are of the same size adding a two's compliment value to another is the same as subtracting the absolute value of one from the absolute value of the other.
In these examples all variables are bytes.
X = 0
OFS = 1
Y = X + OFS Y will have the value of 1.
***********************************************
X = 0
OFS = -1 OFS will have the value 255
Y = X + OFS Y will contain the value 255 (which is -1)
***********************************************
X = 10
OFS = -5 OFS will have the value 251
Y = X + OFS Y will have the value value 5
***********************************************
X = -10 X will have the value 246
OFS = - 15 OFS wil have the value 241
Y = X + OFS Y will have the value 231 which is the same as -25
***********************************************
Bookmarks