Beispiel #1
0
void TestPin::generateMicrobe( FlowCode *code )
{
	const QString pin = dataString("pin");
	const QString port = "PORT" + QString((QChar)pin[1]);
	const QString bit = (QChar)pin[2];
	
	handleIfElse( code, port+"."+bit+" is high", port+"."+bit+" is low", "stdoutput", "altoutput" );
	
#if 0
	QString newCode;
	
	newCode += "btfss "+port+","+bit+" ; Check if pin is clear\n";
	newCode += gotoCode("altoutput") + " ; Pin is low\n";
	newCode += gotoCode("stdoutput") + " ; Pin is high, continue on from this point\n";
	
	code->addCodeBlock( id(), newCode );
#endif
}
void VarComparison::generateMicrobe( FlowCode *code )
{
	QString var1 = dataString("0var1");
	QString var2 = dataString("2var2");
	QString test = dataString("1op");
	
	handleIfElse( code, var1+" "+test+" "+var2, var1+" "+oppOp(test)+" "+var2, "stdoutput", "altoutput" );
	
#if 0
	code->addCode( "if "+var1+" "+test+" "+var2+"\n{\n" );
	code->addCodeBranch( outputPart("stdoutput") );
	code->addCode("}");
	if ( outputPart("altoutput") )
	{
		code->addCode("else\n{");
		code->addCodeBranch( outputPart("altoutput") );
		code->addCode("}");
	}
#endif
	
#if 0
	QString newCode;
	
	if ( FlowCode::isLiteral(var2) ) newCode += "movlw " + var2 + " ; Move literal to register w\n";
	else
	{
		code->addVariable(var2);
		newCode += "movf " + var2 + ",0 ; Move " + var2 + " to register w\n";
	}
	
	if ( FlowCode::isLiteral(var1) ) newCode += "sublw " + var1 + " ; Subtract register w from " + var1 + ", placing result in w\n";
	else
	{
		code->addVariable(var1);
		newCode += "subwf " + var1 + ",0 ; Subtract register w from " + var1 + ", placing result in w\n";
	}
	
	
	if		( test == "==" )
	{
		// check: works
		newCode += "btfss STATUS,2 ; Check if zero flag is set\n";
		newCode += gotoCode("altoutput") + " ; Result from calculation was non-zero; hence comparison is false\n";
		newCode += gotoCode("stdoutput") + " ; Ouput was zero; hence comparison is true, so continue from this point\n";
	}
	else if	( test == "!=" )
	{
		// check: works
		newCode += "btfsc STATUS,2 ; Check if zero flag is clear\n";
		newCode += gotoCode("altoutput") + " ; Result from calculation was zero; hence comparison is false\n";
		newCode += gotoCode("stdoutput") + " ; Output was non-zero; hence comparison is true, so continue from this point\n";
	}
	else if	( test == ">=" )
	{
		// check: works
		newCode += "btfss STATUS,0 ; Check if carry flag is set\n";
		newCode += gotoCode("altoutput") + " ; Result from calculation is negative; hence comparison is false\n";
		newCode += gotoCode("stdoutput") + " ; Result from calculation is positive or zero; so continue from this point\n";
	}
	else if	( test == ">" )
	{
		// check: works
		newCode += "btfss STATUS,0 ; Check if carry flag is set\n";
		newCode += gotoCode("altoutput") + " ; Result is negative; hence comparison is false\n";
		newCode += "btfsc STATUS,2 ; Check if zero flag is set\n";
		newCode += gotoCode("altoutput") + " ; Result is zero; hence comparison is false\n";
		newCode += gotoCode("stdoutput") + " ; Comparison is true, so continue from this point\n";
	}
	else if	( test == "<" )
	{
		// check: works
		newCode += "btfsc STATUS,0 ; Check if carry flag is set\n";
		newCode += gotoCode("altoutput");
		newCode += gotoCode("stdoutput");
	}
	else if	( test == "<=" )
	{
		// check: works
		newCode += "btfsc STATUS,2 ; Check if result is zero\n";
		newCode += gotoCode("stdoutput") + " ; Result is zero; hence comparison is true\n";
		newCode += "btfsc STATUS,0 ; Check if carry flag is set\n";
		newCode += gotoCode("altoutput") + " ; Result is positive (not zero, has already tested for this); hence comparison is false\n";
		newCode += gotoCode("stdoutput") + " ; Result is negative, hence comparison is true\n";
	}
	
	code->addCodeBlock( id(), newCode );
#endif
}