So, I'm new to assembly programming, as well as the concept of "two's complement" representation of negative numbers, and I'm a little confused.
In the book that I'm reading on the subject of assembly (and on every online resource I've consulted), it is explained that you can tell whether or not a number is negative by looking at its most significant bit; if that bit is 1, it's negative (signed), otherwise, it's positive (unsigned). This doesn't make sense to me, however.
To illustrate my confusion, imagine the unsigned representation of 255: 11111111
That's a positive, unsigned value, but its most significant bit is set. According to the two's complement rules I've been reading about, that should make this number negative rather than positive, but it IS possible to have unsigned values like this with the most significant bit set (if you couldn't do this, an unsigned 8-bit integer could only represent the numbers 0-127). So how does this work? How can I tell if a number is signed or simply unsigned with the most significant bit set? And, possibly more importantly, how can a computer tell the difference? Am I just missing something?
256=1 0000 0000=> 9 bits). This demonstrates 8 bit limit being 255 nicely. But you can look at the same operation in "signed" mode as -1 + 1 = 0. And in the similar way breaking the signed limit: 127 + 1 = -128 (0111 1111+ 1 =1000 0000) -> makes sense in "unsigned" view, as it's 127 + 1 = 128. So the CPU is doing the same add/sub operation for both "signed" and "unsigned" numbers. - Ped7g