Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Test program for Digital Mars D (DMD)
- ** which shows that it has some sort of bug.
- */
- import std.stdio;
- char filter(uint i) {
- enum bloop = '#'; // traditional substitute for non-printable (hak tradition)
- enum bleck = '.'; // for zero as it is null and not "bloop", but non-printable
- i = i & 0x7f;
- if (i == 0)
- return bleck;
- if (i < 32)
- return bloop;
- else
- return cast(char)i;
- }
- string ex_18_1b() {
- string textReturned;
- uint r[3];
- uint r1, r2, r3; // NOTE: needed for a workaround of an apparent bug!
- asm {
- mov EAX, 0;
- cpuid;
- mov r1, EBX;
- mov r2, EDX;
- mov r3, ECX;
- }
- r[0] = r1;
- r[1] = r2;
- r[2] = r3;
- textReturned = decode(r, 3);
- return textReturned;
- }
- string decode(uint[] r, int n) {
- uint wrd;
- int y, x;
- string textReturned;
- bool verbose = true; // NOTE: just to make the bug transparent.
- for (y = 0; y < n; y++) {
- wrd = r[y];
- if (verbose)
- writefln("\tword[%d]:0x%x", y, wrd);
- for (x = 0; x < 4; x++) {
- textReturned ~= filter(wrd);
- wrd >>= 8;
- }
- }
- return textReturned;
- }
- string ex_18_1() {
- string textReturned;
- uint r[3];
- asm {
- mov EAX, 0;
- cpuid;
- mov r[0], EBX;
- mov r[1], EDX;
- mov r[2], ECX;
- }
- textReturned = decode(r, 3);
- return textReturned;
- }
- void main()
- {
- writefln("Temporary D test program by \"K1pp\".");
- writefln("\tBased on Ex.18-1 in Brey's old book.");
- writefln("This illustrates an annoying DMD bug, or something.\n");
- writefln("CPUID based on Ex 18-1:\n\t\"%s\".\n", ex_18_1() );
- writefln("CPUID based on Ex 18-1, variant 'b':\n\t\"%s\".\n", ex_18_1b() );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement