News for hackers. Stuff that matters.
Re:C-based Virtual Machine for Notch's DCPU-16 by Triave on Wednesday April 04, 2012 @03:29PM (#3799388)
Note that this VM can depend on behaviour that is explicitly left undefined by the C11 standard. For example, this DCPU-16 program can cause a shift by an amount greater than the width of uint16_t:

SET A, 0x1 SHL A, 0x100

Re:C-based Virtual Machine for Notch's DCPU-16 by lifthrasiir on Thursday April 05, 2012 @03:09AM (#3801632)
The Java Language Specification indeed states that the shift amount should be ANDed with 31 or 63, depending on a type of the left-hand operand. I guess Notch did not intend this behavior, however.

http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html...

Re:C-based Virtual Machine for Notch's DCPU-16 by eridius on Wednesday April 04, 2012 @04:21PM (#3799651)
This will, of course, set both A and O to 0.
Re:C-based Virtual Machine for Notch's DCPU-16 by Triave on Wednesday April 04, 2012 @04:50PM (#3799765)
Depends how left shift is implemented: on some processors (including x86), only the lowest order bits of the number of positions to shift by are used. In Java:

char A = 1; A = ((char) ((A << 32) & 0xFFFF)); System.out.println(Integer.toHexString(A));

actually outputs 1.