> asm mov ax ,[ WORD PTR rndval ]<p>> asm mov dx ,[ WORD PTR rndval +2]<p>> asm mov bx , ax<p>> asm dec bl<p>> asm mov [ BYTE PTR y ], bl // low 8 bits - 1 = y<p>> <i>asm mov bx , ax</i><p>> asm mov cx , dx<p>> asm mov [ BYTE PTR x ], ah // next 9 bits = x<p>> asm mov [ BYTE PTR x +1] , dl<p>I don't understand the need for the second <i>asm mov bx , ax</i> : BX is not used afterwards. Same for CX, it is never used.<p>> uint32_t rndval = 1;<p>> uint16_t x,y;<p>> do<p>> {<p>> y = rndval & 0x00F; // Y = low 8 bits<p>> x = rndval & 0x1F0; // X = High 9 bits<p>Er... no, if you do that, you only get the lowest <i>4</i> bits in <i>y</i>, and then you only get <i>5</i> bits in <i>x</i> (and not the right ones, of course).<p>It should be:<p><pre><code> y = rndval & 0x000000FF; // Y = low 8 bits
</code></pre>
And then you have a 'problem' for x, because you must shift it right, otherwise it doesn't fit in a 16-bit variable:<p><pre><code> x = rndval & 0x0001FF00; // X = bits 8 to... 16 > 15, irk
</code></pre>
So you should just do :<p><pre><code> x = rndval >> 8; // X = bits 8 to 17, in their right place</code></pre>