evolve4src/src/evolve_simulator/kforth_mutate.cpp
static void modify_single_instruction(EVOLVE_RANDOM *er, KFORTH_MUTATE_OPTIONS *kfmo,
				KFORTH_PROGRAM *kfp, int cb, int pc)
{
	int delta;

	ASSERT( er != NULL );
	ASSERT( kfmo != NULL );
	ASSERT( kfp != NULL );
	ASSERT( cb >= 0 && cb < kfp->nblocks );
	ASSERT( pc >= 0 && pc < kfp->block_len[cb] );

	if( kfp->opcode[cb][pc] == 0 ) {
		delta = CHOOSE(er, -XLEN, XLEN);
		if( delta == 0 ) {
			/*
			 * swap sign
		 	 */
			kfp->operand[cb][pc] = -kfp->operand[cb][pc];

		} else {
			/*
			 * Increment or Decrement by 1 - XLEN
			 */
			kfp->operand[cb][pc] += delta;
		}
	} else {
		kfp->opcode[cb][pc] = (unsigned char) CHOOSE(er, 1, kfmo->max_opcodes);
	}

}
/*
 * modify an existing instruction.
 *
 *	- modify the instuction (cb, pc)
 *	- (cb, pc) must be a valid instruction
 *	- pick a random number between -XLEN and XLEN. If 0, swap sign, otherwise add it to the
 *	  number.
 *	- if not a number, change instruction to something different (but not to a number)
 *
 * This keeps numbers as numbers and instructions as instructions.
 */
modify an existing instruction.
- modify the instuction (cb, pc)
- (cb, pc) must be a valid instruction
- pick a random number between -XLEN and XLEN. If 0, swap sign, otherwise add it to the
number.
- if not a number, change instruction to something different (but not to a number)

This keeps numbers as numbers and instructions as instructions.
modify an existing instruction . - modify the instuction ( cb pc ) - ( cb pc ) must be a valid instruction - pick a random number between - XLEN and XLEN . If 0 swap sign otherwise add it to the number . - if not a number change instruction to something different ( but not to a number ) This keeps numbers as numbers and instructions as instructions .
static void modify_single_instruction(EVOLVE_RANDOM *er, KFORTH_MUTATE_OPTIONS *kfmo,
				KFORTH_PROGRAM *kfp, int cb, int pc)
{
	int delta;
	ASSERT( er != NULL );
	ASSERT( kfmo != NULL );
	ASSERT( kfp != NULL );
	ASSERT( cb >= 0 && cb < kfp->nblocks );
	ASSERT( pc >= 0 && pc < kfp->block_len[cb] );
	if( kfp->opcode[cb][pc] == 0 ) {
		delta = CHOOSE(er, -XLEN, XLEN);
		if( delta == 0 ) {
			kfp->operand[cb][pc] = -kfp->operand[cb][pc];
		} else {
			kfp->operand[cb][pc] += delta;
		}
	} else {
		kfp->opcode[cb][pc] = (unsigned char) CHOOSE(er, 1, kfmo->max_opcodes);
	}
}
static void modify_single_instruction ( EVOLVE_RANDOM * er , KFORTH_MUTATE_OPTIONS * kfmo , KFORTH_PROGRAM * kfp , int cb , int pc ) { int delta ; ASSERT ( er != NULL ) ; ASSERT ( kfmo != NULL ) ; ASSERT ( kfp != NULL ) ; ASSERT ( cb >= 0 && cb < kfp -> nblocks ) ; ASSERT ( pc >= 0 && pc < kfp -> block_len [ cb ] ) ; if ( kfp -> opcode [ cb ] [ pc ] == 0 ) { delta = CHOOSE ( er , - XLEN , XLEN ) ; if ( delta == 0 ) { kfp -> operand [ cb ] [ pc ] = - kfp -> operand [ cb ] [ pc ] ; } else { kfp -> operand [ cb ] [ pc ] += delta ; } } else { kfp -> opcode [ cb ] [ pc ] = ( unsigned char ) CHOOSE ( er , 1 , kfmo -> max_opcodes ) ; } }
modify an existing instruction.
modify an existing instruction .
/*
			 * swap sign
		 	 */ /*
			 * Increment or Decrement by 1 - XLEN
			 */