Signed add/sub? 
Author Message
 Signed add/sub?

Hi.

Is it possible to perform a signed addition/subtracktion?
Like:
         +12 + (-14) = +12 - 14 = -2
or  
         +3 - (-8) = +3 + 8 = +11

Do I have to do this manually?
Any opcodes?

--
Netrunner

***********************************************

<WWW: http://www.*-*-*.com/ ~hugopa           >
***********************************************



Tue, 10 Aug 1999 03:00:00 GMT  
 Signed add/sub?

Quote:

> Is it possible to perform a signed addition/subtracktion?
> Any opcodes?

Exactly same as for unsigned - no difference needed.


Tue, 10 Aug 1999 03:00:00 GMT  
 Signed add/sub?

Quote:

> Hi.

> Is it possible to perform a signed addition/subtracktion?
> Like:
>          +12 + (-14) = +12 - 14 = -2
> or
>          +3 - (-8) = +3 + 8 = +11

> Do I have to do this manually?
> Any opcodes?

Hi,

if you represent the negative numbers in 2's complement, you can use the
same ADD and SUB ( ADC and SBB) instructions. To make a positive number
negative (or vice versa), you can use the NEG (negate) instruction.
Hope this helps.
--
Regards,
---------------------------------------------------
Danny Hendrickx   |                               |
Alcatel Telecom   |                               |

-----------------------------------------------------------------
I wanted to take my wife on a world trip for the holidays,
but she wanted to go somewhere else...
-----------------------------------------------------------------



Fri, 13 Aug 1999 03:00:00 GMT  
 Signed add/sub?


Quote:

>Hi.

>Is it possible to perform a signed addition/subtracktion?
>Like:
>         +12 + (-14) = +12 - 14 = -2
>or  
>         +3 - (-8) = +3 + 8 = +11

Intel uses so called two's complement notation for singed numbers. This
has a benefit that addition and subtraction works exactly same way on
both unsigned and signed numbers. The only difference is in case if you
want to do overflow checking. With signed numbers you check the overflow
flag and with unsigned numbers the carry flag.

You need to make the difference when comparing numbers (ja/jb for
unsigned, jg/jl for signed), when multiplying or dividing (mul/div for
unsigned, imul/idiv for signed) and of course in I/O.

Osmo



Sat, 14 Aug 1999 03:00:00 GMT  
 Signed add/sub?

Quote:

>Is it possible to perform a signed addition/subtracktion?
>Like:
>         +12 + (-14) = +12 - 14 = -2
>or  
>         +3 - (-8) = +3 + 8 = +11

>Do I have to do this manually?
>Any opcodes?

No you don't.  All you have to do is to use signed numbers in your
operands.

If you want to add +12 and -14, you could use:
     MOV  AX, 12
     MOV  BX, -14
     ADD  AX, BX

But of course you have to treat your numbers as signed as well.
If the most significant (sign) bit is 0, the value is positive.  If the
sign bit is 1, the value is negative and you get the two's complement
form to get the magnitude (i.e. FFFEh = -2)

YO!
Erwin



Sun, 15 Aug 1999 03:00:00 GMT  
 Signed add/sub?


Quote:
>Hi.

>Is it possible to perform a signed addition/subtracktion?
>Like:
>         +12 + (-14) = +12 - 14 = -2
>or  
>         +3 - (-8) = +3 + 8 = +11

>Do I have to do this manually?
>Any opcodes?

>--
>Netrunner

>***********************************************

><WWW: http://login.eunet.no/~hugopa           >
>***********************************************

Try using the NEG opcode then sub/adding

--
******************************************************
Ryan Cumming, Newbie Hacker and Programmer Extrodinare
******************************************************



Tue, 17 Aug 1999 03:00:00 GMT  
 Signed add/sub?



Quote:
>Hi.

>Is it possible to perform a signed addition/subtracktion?
>Like:
>         +12 + (-14) = +12 - 14 = -2
>or  
>         +3 - (-8) = +3 + 8 = +11

>Do I have to do this manually?
>Any opcodes?

Try ADD and SUB, the whole reason we use a 2's compliment numbering
system is that they can be added like this.
(As apposed to a sign/value form)

#####  ###  #   #
  #    ##   # # #
  #    #    #   #

It's better to burn out than to fade away...



Sun, 22 Aug 1999 03:00:00 GMT  
 Signed add/sub?



: >Hi.
: >
: >Is it possible to perform a signed addition/subtracktion?
: >Like:
: >         +12 + (-14) = +12 - 14 = -2
: >or  
: >         +3 - (-8) = +3 + 8 = +11
: >
: >Do I have to do this manually?
: >Any opcodes?

: Try ADD and SUB, the whole reason we use a 2's compliment numbering
: system is that they can be added like this.
: (As apposed to a sign/value form)

: #####  ###  #   #
:   #    ##   # # #
:   #    #    #   #

: It's better to burn out than to fade away...

--

        In 2's complement system, the 2 operations can be done
        as if the sign disappeared, since the result is still
        correct regardless of whether you TREAT the number as
        a pure binary number or as a 2's complement number.
        The status register has different flags to indicate the
        condition of the result in both pure binary and signed
        number. If you need to treat the number as signed, you
        can check for the sign-flag and overflow-flag otherwise
        check for the carry-flag.

--
Terence



Wed, 08 Sep 1999 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Signed add/sub?

2. Sign magnitude add & sub

3. How do I add two signed bitvectors

4. Adding a signed word to unsigned word...

5. Add/sub with Xs

6. Just curious: ADD/SUB internals

7. Help with SUB and ADD

8. VHDL RTL model of add/sub division

9. Is there a way to access/modify/add variables to caller from a sub function

10. Good Sign or Bad Sign?

11. $(TELEGEN2)/lib/rt.sub versus $(TELEGEN2)/lib/h_rt.sub

12. sorting by sub-sub-list elements

 

 
Powered by phpBB® Forum Software