Re: A83: Just Curious...


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

Re: A83: Just Curious...




no.. it is not _only_ bit 7. you can see on bit 7 if the number is negative but
it is _not_ like this:

%00000111  ; 7
%10000111  ; This is _not_ -7

the way of representing negative numbers that is commonly used in all computer
hardware of today is 2 complement. that is:

%00000111  ; The number 7

%11111000  ; first invert.
%11111001  ; add 1.

%11111001  ; This is -7.

When you represent a negative number like this, you can use the same algoritm to
both add and subtract. and you get rid of the problem of having two zeros
%10000000 and %00000000 would both be zero if you used the first method..
(not very effective.)

//Olle

Scott Dial wrote:
> 
> I thought of that, but a negative number in our respect is simply
> denoted by bit 7's value. So, how would you "add" the 0-6 as if they
> were negative then??? It is the same as if they were positive.
> 
> Olle Hedman wrote:
> >
> > A subtraction is normally done by adding a negative number.
> >
> > //Olle
> >
> > Scott Dial wrote:
> > >
> > > I was playing around the other day and I was thinking about how a byte
> > > is added to another byte, and I wrote some z80 code that used bit-level
> > > commands to add a byte to another (Basically, doesn't use add). I got to
> > > trying to figure out subtracting and I got stumped... This really as no
> > > point, but I was just wondering how a subtraction is performed. And,
> > > don't bother telling me how "unoptimized" it is and I don't need some
> > > smart-ass to say, "Why don't you just say 'add a,b'?"!
> > >
> > >  ld a,1
> > >  ld b,1
> > > AddAtoB:
> > >  push bc
> > >  push af
> > >  xor b          ;XOR A and B
> > >  pop de
> > >  pop bc
> > >  push af
> > >  push de
> > >  pop af
> > >  and b          ;AND A and B
> > >  rs             ;RS (AND A and B)
> > >  pop bc         ;    |
> > >  or b           ;OR -/ and B
> > >  ret            ;A = A + B
> > >
> > > --
> > > Scott "_Wrath_" Dial
> > > homosapian@geocities.com
> > > ICQ#3608935
> > > http://www.geocities.com/~homosapian/
> 
> --
> Scott "_Wrath_" Dial
> homosapian@geocities.com
> ICQ#3608935
> http://www.geocities.com/~homosapian/
> ________________________________________________________
> NetZero - We believe in a FREE Internet.  Shouldn't you?
> Get your FREE Internet Access and Email at
> http://www.netzero.net/download.html


Follow-Ups: References: