Re: A83: Just Curious...


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

Re: A83: Just Curious...




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/


Follow-Ups: References: