[Avida-SVN] r3300 - development/source/cpu

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Tue Jun 9 10:13:31 PDT 2009


Author: hjg
Date: 2009-06-09 13:13:30 -0400 (Tue, 09 Jun 2009)
New Revision: 3300

Modified:
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
Log:
New instruction to enable organisms to query how many members there are in a group with a given group-id.

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2009-06-07 18:11:35 UTC (rev 3299)
+++ development/source/cpu/cHardwareCPU.cc	2009-06-09 17:13:30 UTC (rev 3300)
@@ -569,6 +569,7 @@
 		
 		// Group formation instructions
 		tInstLibEntry<tMethod>("join-group", &cHardwareCPU::Inst_JoinGroup, nInstFlag::STALL),
+		tInstLibEntry<tMethod>("orgs-in-my-group", &cHardwareCPU::Inst_NumberOrgsInMyGroup, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("orgs-in-group", &cHardwareCPU::Inst_NumberOrgsInGroup, nInstFlag::STALL),
 		
     // Must always be the last instruction in the array
@@ -8945,7 +8946,7 @@
 
 //! Gets the number of organisms in the current organism's group 
 //! and places the value in the ?CX? register
-bool cHardwareCPU::Inst_NumberOrgsInGroup(cAvidaContext& ctx)
+bool cHardwareCPU::Inst_NumberOrgsInMyGroup(cAvidaContext& ctx)
 {
 	int num_orgs = 0;
 	assert(m_organism != 0);
@@ -8959,3 +8960,19 @@
 	GetRegister(num_org_reg) = num_orgs;
 	return true;
 }
+
+
+//! Gets the number of organisms in the group of a given id
+//! specified by the ?BX? register and places the value in the ?CX? register
+bool cHardwareCPU::Inst_NumberOrgsInGroup(cAvidaContext& ctx)
+{
+	int num_orgs = 0;
+	assert(m_organism != 0);
+	const int group_id = FindModifiedRegister(REG_BX);
+	const int num_org_reg = FindModifiedRegister(REG_CX);
+
+	num_orgs = m_world->GetPopulation().NumberOfOrganismsInGroup(group_id);
+  
+	GetRegister(num_org_reg) = num_orgs;
+	return true;
+}

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2009-06-07 18:11:35 UTC (rev 3299)
+++ development/source/cpu/cHardwareCPU.h	2009-06-09 17:13:30 UTC (rev 3300)
@@ -853,8 +853,9 @@
 	//! An organism joins a group by setting it opinion to the group id. 
 	bool Inst_JoinGroup(cAvidaContext& ctx);
 	//! Returns the number of organisms in the current organism's group
-	bool Inst_NumberOrgsInGroup(cAvidaContext& ctx);
-		
+	bool Inst_NumberOrgsInMyGroup(cAvidaContext& ctx);
+	//! Returns the number of organisms in the current organism's group
+	bool Inst_NumberOrgsInGroup(cAvidaContext& ctx);		
 	
 	
 };




More information about the Avida-cvs mailing list