A86: Re: Re: divide by 2
[Prev][Next][Index][Thread]
A86: Re: Re: divide by 2
thanks, I was worried it was something easy like that. Binary is one of
those things that I know i should learn better, but until now I just haven't
had any motivation to do so
,billybobIV
chad@dirks.com
http://chad.dirks.com
----- Original Message -----
From: David Phillips <david@acz.org>
To: <assembly-86@lists.ticalc.org>
Sent: Wednesday, March 03, 1999 5:45 PM
Subject: A86: Re: divide by 2
>
>Hehe, that's a "classic" newbie question. If you're talking floating
point,
>just use the call...
>
>_FPDIV -- divide OP1 by OP2
>
>For registers, this is very simple. Think in binary when you program. If
>you shift a binary number left, it's multiplied by two. If you shift it
>right, it's...drumroll...divided by two...
>
> ld a,5
> or a ; clear carry flag (probably not needed)
> rra ; divide by two!!!
>
> ld c,17
> srl c ; divide by two
>
> ld b,5
> sra b ; multiply by two
>
> ld a,78
> rra ; divide by 8
> rra
> rra
> and %00011111 ; mask off excess bits
>
>If you're using A, you can use <rla> and <rra>, which is good because
>they're one byte, 4 t-state instructions. Just remember that the carry
flag
>is rotated into the other end, so if you are doing multiple shifts, you
will
>probably have to mask off (AND) the extra bits. <sra> and <srl> can be
used
>with any register and set the other bit to 0 (which you want), but take up
>two bytes and 8 t-states (twice an RLA or RRA).
>
>>
Follow-Ups: