ASM access to array

Matthias Pleh sufu at alter.com
Wed Feb 2 03:23:42 PST 2011


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


More information about the Digitalmars-d-learn mailing list