[Avida-SVN] r1389 - in branches/uml/source: cpu main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Mon Mar 5 12:32:37 PST 2007


Author: hjg
Date: 2007-03-05 15:32:36 -0500 (Mon, 05 Mar 2007)
New Revision: 1389

Modified:
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/cpu/cHardwareCPU.h
   branches/uml/source/main/cOrganism.cc
   branches/uml/source/main/cOrganism.h
Log:
New instruction - jumpIndex


Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2007-03-05 14:03:47 UTC (rev 1388)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2007-03-05 20:32:36 UTC (rev 1389)
@@ -361,7 +361,9 @@
 	cInstEntryCPU("addTransLab", &cHardwareCPU::Inst_AddTransitionLabel, false, 
 					"Add a transition label"),
 	cInstEntryCPU("addTrans", &cHardwareCPU::Inst_AddTransition, false, 
-					"Add a transition")													
+					"Add a transition"),
+	cInstEntryCPU("jump", &cHardwareCPU::Inst_JumpIndex, false, 
+					"Jump to a position in the list"),																	
   };
   
   const int n_size = sizeof(s_n_array)/sizeof(cNOPEntryCPU);
@@ -3452,6 +3454,46 @@
 	return true;
 }
 
+bool cHardwareCPU::Inst_JumpIndex(cAvidaContext& ctx)
+{
+	const int reg_used = FindModifiedRegister(REG_AX);
+	const int reg_jump = FindModifiedRegister(REG_BX);
+	int jump_amount = GetRegister(reg_jump);
+
+//	int jump_amount = 
+	
+	switch (reg_used){
+	case 0:
+		// decrement the triggers vector index
+		organism->jumpTrigger(jump_amount);
+		break;
+	case 1:
+		// decrement the guards vector index
+		organism->jumpGuard(jump_amount);
+		break;
+	case 2:
+		// decrement the actions vector index
+		organism->jumpAction(jump_amount);
+		break;
+	case 3:
+		// decrement the transition labels index
+		organism->jumpTransitionLabel(jump_amount);
+		break;	
+	case 4:
+		// decrement the original state index
+		organism->jumpOriginState(jump_amount);
+		break;
+	case 5:
+		// decement the destination state index
+		organism->jumpDestinationState(jump_amount);
+		break;
+   // default:
+		// we should never get here...
+	}
+	return true;
+}
+
+
 bool cHardwareCPU::Inst_AddTransitionLabel(cAvidaContext& ctx)
 {
 	return organism->addTransitionLabel();

Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h	2007-03-05 14:03:47 UTC (rev 1388)
+++ branches/uml/source/cpu/cHardwareCPU.h	2007-03-05 20:32:36 UTC (rev 1389)
@@ -475,6 +475,7 @@
   bool Inst_AddState(cAvidaContext& ctx);
   bool Inst_Next(cAvidaContext& ctx);
   bool Inst_Prev(cAvidaContext& ctx);
+  bool Inst_JumpIndex(cAvidaContext& ctx);
   bool Inst_AddTransitionLabel(cAvidaContext& ctx);
   bool Inst_AddTransition(cAvidaContext& ctx);
 

Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2007-03-05 14:03:47 UTC (rev 1388)
+++ branches/uml/source/main/cOrganism.cc	2007-03-05 20:32:36 UTC (rev 1389)
@@ -703,6 +703,125 @@
 	return true;
 }
 
+
+bool cOrganism::jumpTrigger(int jump_amount)
+{
+	if (triggers.size() == 0) {
+		return false;
+	}
+	
+	if (jump_amount > 0) { 
+		trigger_index = trigger_index + (jump_amount % triggers.size());
+		// index is greater than vector
+		if (trigger_index >= triggers.size()) { 
+			trigger_index -= triggers.size();
+		} else if(trigger_index < 0) { 
+			trigger_index += triggers.size();
+		}
+	}	
+	
+/*	
+	if (trigger_index <= 0) {
+		trigger_index = triggers.size();
+	}
+	trigger_index--;*/
+	
+	return true;
+}
+
+
+
+bool cOrganism::jumpGuard(int jump_amount)
+{
+	if (guards.size() == 0) {
+		return false;
+	}
+	
+	if (jump_amount > 0) { 
+		guard_index = guard_index + (jump_amount % guards.size());
+		// index is greater than vector
+		if (guard_index >= guards.size()) { 
+			guard_index -= guards.size();
+		} else if(guard_index < 0) { 
+			guard_index += guards.size();
+		}
+	}	
+	
+	return true;
+}
+
+bool cOrganism::jumpAction(int jump_amount)
+{
+	int act_size = actions.size();
+	if (actions.size() == 0) {
+		return false;
+	}
+	if (jump_amount > 0) { 
+		action_index = action_index + (jump_amount % actions.size());
+		// index is greater than vector
+		if (action_index >= actions.size()) { 
+			action_index -= actions.size();
+		} else if(action_index < 0) { 
+			action_index += actions.size();
+		}
+	}		
+	return true;
+}
+
+bool cOrganism::jumpTransitionLabel(int jump_amount)
+{
+	if (transition_labels.size() == 0) {
+		return false;
+	}
+	if (jump_amount > 0) { 
+		trans_label_index = trans_label_index + (jump_amount % transition_labels.size());
+		// index is greater than vector
+		if (trans_label_index >= transition_labels.size()) { 
+			trans_label_index -= transition_labels.size();
+		} else if(trans_label_index < 0) { 
+			trans_label_index += transition_labels.size();
+		}
+	}	
+	
+	return true;
+}
+
+
+bool cOrganism::jumpOriginState(int jump_amount) 
+{
+	if (total_states == 0) {
+		return false;
+	}
+	if (jump_amount > 0) { 
+		orig_state_index = orig_state_index + (jump_amount % total_states);
+		// index is greater than vector
+		if (orig_state_index >= total_states) { 
+			orig_state_index -= total_states;
+		} else if(orig_state_index < 0) { 
+			orig_state_index += total_states;
+		}
+	}		
+	return true;
+}
+
+bool cOrganism::jumpDestinationState(int jump_amount) 
+{
+	if (total_states == 0) {
+		return false;
+	}
+	if (jump_amount > 0) { 
+		dest_state_index = dest_state_index + (jump_amount % total_states);
+		// index is greater than vector
+		if (dest_state_index >= total_states) { 
+			dest_state_index -= total_states;
+		} else if(dest_state_index < 0) { 
+			dest_state_index += total_states;
+		}
+	}	
+	
+	return true;
+}
+
 std::string cOrganism::getTrigger()
 {
 	if (triggers.size() == 0) {

Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h	2007-03-05 14:03:47 UTC (rev 1388)
+++ branches/uml/source/main/cOrganism.h	2007-03-05 20:32:36 UTC (rev 1389)
@@ -255,6 +255,15 @@
   bool prevOriginState();
   bool prevDestinationState();
   
+// The jump functions jump the index of the various vectors either forward (+ int) or backwards (- int)
+  bool jumpGuard(int);
+  bool jumpAction(int);
+  bool jumpTrigger(int);
+  bool jumpTransitionLabel(int);
+  bool jumpOriginState(int);
+  bool jumpDestinationState(int);
+    
+  
 // The get functions get the value of the index of various vectors  
   std::string getTrigger();
   std::string getGuard();




More information about the Avida-cvs mailing list