unsigned and signed numbers have seperate intructions for multiplication and division
unsigned and signed both use the same addition and subtraction instruction

^
how does the computer know whether a number is signed or not?? does it matter?

also when i try and add using 2's complement i get the incorrect value? why is this!? and how does the cpu know

Human Addition with signed numbers
-9
+ -4
-------
-13

CPU addition with signed numbers using 2's complement to get the negative value of both numbers
-9
+ -4
-------
3    <-- wrong value!

also one last thing! 2's complement isnt another form of a number for example. intel pc's use 2's complement for their numbers? <-- this statement would be false because they just use regular binary....2's complement is only use when u need to show signed values!

Posted on 2010-12-02 16:44:57 by dougfunny

Not to be terse, however, simply google for binary addition and subtraction or twos complement

You will find a wealth of information on this topic that explains it in thorough detail...
Posted on 2010-12-02 18:21:51 by p1ranha
dougfunny,

If you'll follow p1ranha's advice, you'll probably learn about another kinds of signed number's binary representations, like one's complement or sign-and-magnitude. You may even stumble upon balanced ternary or another useful-but-weird representations as well. ;)
Posted on 2010-12-03 05:54:33 by baldr
-9+(-4)=3 because overflow happens and the result is wrong and out of range. Each architecture defines certain range for signed operations.

You can use some add/subtract instruction and consider its operands as unsigned. Besides CPU defines some extra flag bits which are automatically set or reset and if a programmer considers operands as signed numbers he can look at those bits and interpret the result by them. On the contrary if the programmer considers the numbers unsigned, the result maybe OK and he does not need to look at those extra bits like sign bit and overflow bit.

Anyway a programmer should know that there is a range for add/subtract/multiply/divide for signed and also for unsigned numbers.  This range is determined by the size of the registers he is working with.
Posted on 2011-06-11 06:23:17 by logicman112
How does -9 + (-4) get to be out of range? How are we determining that the result is "wrong"? Works for me!

Best,
Frank

``global _startextern printfsection .datafmt db `%d\n`, 0section .text_start:nopmov eax, -9mov ebx, -4add eax, ebxpush eaxpush fmtcall printfadd esp, 4 * 2mov eax, 1int 80h``

Posted on 2011-06-11 07:38:06 by fbkotler