# Assembly: Rotating numbers

Printable View

• 07-19-2008, 08:17 AM
unix
Assembly: Rotating numbers
Hi.

I need rotate the six-bits from number Db to Ab.
My MASD source code:

;Input: Db: Six-bit number (xx000011)
;Output: Ab: six-bit number (xx110000) rotated
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
C=D.B ;xx000011
A=0.B P=(16-6)
{ ?CBIT=1.0 -> { ABIT=1.0 }
CSRB.B A+A.B P+1 UPNC }
ASRB.B ;xx110000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

.... another short algorithm?
I think that my solution is very... long? :-(

Cheers,
- Gaak -
• 07-19-2008, 01:17 PM
unix
Re: Assembly: Rotating numbers
Hello,

On Jul 19, 4:17*am, GaaK <Comp...@gaak.org> wrote:[color=blue]
> Hi.
>
> I need rotate the six-bits from number Db to Ab.[/color]

I think your code reverses the bits rather than rotating. Your code
seems OK, not too much to optimize, except that if you only deal with
6-bit numbers, you can unroll the loop to gain a few cycles. On the
other hand, I would definitely use a table with all 64 possible
combinations already mirrored (actually, there are 32 different
combinations, but the algorithm will be faster if you use all 64 in a
table).
After all, such table will only use 64 bytes, and will give you much
improved performance.
If you need to do it with more bits, you can use an algorithm like in
the link below.

[url]http://aggregate.org/MAGIC/#Bit%20Reversal[/url]

The algorithm is originally for 32-bit numbers, where a table would be
impractical for obvious reasons (8GB size :-), but I think you won't
have any troubles adapting it for 6 bits.
In my opinion, you'll never beat the table lookup.

Regards,
Claudio
[color=blue]
> My MASD source code:
>
> ;Input: *Db: Six-bit number (xx000011)
> ;Output: Ab: six-bit number (xx110000) rotated
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> C=D.B *;xx000011
> A=0.B P=(16-6)
> { ?CBIT=1.0 -> { ABIT=1.0 }
> * CSRB.B A+A.B P+1 UPNC }
> ASRB.B ;xx110000
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> ... another short algorithm?
> I think that my solution is very... long? :-(
>
> Cheers,
> - Gaak -[/color]