private int setC(int instruction, int c) throws Exception {
        if(c < 0) c ^= 0xffff0000; // c will be sign extended from 16 bit value
        if((c & ~0xffff) != 0) {
            throw new Exception("Illegal operand for instruction");
        }
        instruction = (instruction & ~0xffff) | c;
        return instruction;
    }