As bearophile notet, unittest are always good!!
But for the start, I always liked to make some pretty-printing functions ...
... so this is my version


import std.stdio;

uint rotl_d(uint value,ubyte rotation){
    return (value<<rotation) | (value>>(value.sizeof*8 - rotation));
}

uint rotl_asm(uint value,ubyte rotation){
    asm{
        mov EAX, value;   // get first argument
        mov CL , rotation; // how many bits to move
        rol EAX, CL;
    }// return with result in EAX
}

void bin_writeln(string info,uint value, bool nl){
    writefln("%1s: %02$32b%3$s",info,value,nl?"\n":"");
}

int main(string[] argv){
    uint a=0xc0def00d;
    bin_writeln("value a",a           ,false);
    bin_writeln("value b",rotl_d(a,1),true);
    //
    bin_writeln("value a",a             ,false);
    bin_writeln("value b",rotl_asm(a,1),true);
    return 0;
}

greets
Matthias

Reply via email to