Re: A83: Just Curious...
[Prev][Next][Index][Thread]
Re: A83: Just Curious...
Another fun thing to do, is to do calculations in 10 complement (just to annoy
people :)
like this. say we want to calculate 98-43
we take 43, invert it to 56 (when using our ordinary numbers we have 10 of them
instead of two. so 0 inverted is 9, 1 inv. is 8 and so on.)
add 1, we have now 57
98
+57
----
155
A
|
+-- "overflow" we only use 2 digit numbers, ignore.. :)
voila! we have the answer! 55!
neat... isn't it? :)
//Olle
Olle Hedman wrote:
>
> 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
References: