[A83] Re: Signed division by a power of two.


[Prev][Next][Index][Thread]

[A83] Re: Signed division by a power of two.



sla puts the old bit 7 into the carry.

-----Original Message-----
From: assembly-83-bounce@lists.ticalc.org
[mailto:assembly-83-bounce@lists.ticalc.org] On Behalf Of Tijl Coosemans
Sent: Tuesday, August 12, 2003 2:46 PM
To: assembly-83@lists.ticalc.org
Subject: [A83] Re: Signed division by a power of two.

On Tue, 12 Aug 2003 16:01:46 -0500, Matthew Marshall wrote:

> Or does that way even work?  I have been having a hard time catching
> onto this idea of signed numbers.

It's exactly the same as with normal binary numbers where

0010 0110 = 32+4+2

With signed numbers you give bit 7 the value -128 instead of 128

1000 0000 = -128
1000 0001 = -128+1
1010 1010 = -128+32+8+2

If you use 16 bit signed numbers you give bit 15 value -32768 instead of
32768.

Adding, subtracting and shifting are exactly the same, except for shift
right which has to preserve bit 7. The "sra" instruction does exactly
that as opposed to the "srl" instruction which is just a logical shift.
Of course you also need to take care of overflows: -125*2 doesn't fit in
an 8 bit register for example. I'm not sure but maybe "sla" warns you
about that with the carry flag?





References: