-1 can be represented in 4 bit binary as (2's complement) 1111
15 is also represented as 1111.
So, how does CPU differentiate between 15 and -1 when it gets values from memory?
The CPU doesn't care whether a byte holds -1 or 15 when it moves it from one place to another. There's no such thing as a "signed move" (to a location of the same size - there is a signed move for larger or smaller destinations).
The CPU only cares about the representation when it does arithmetic on the byte. The CPU knows whether to do signed or unsigned arithmetic according to the op-code that you (or the compiler on your behalf) chose.
1.4m articles
1.4m replys
5 comments
57.0k users