Plov018 : BIT operations
This is the only missing part of Plov, as for now: bit operations. OK, you could do the same with assignment operations but this is easier on the eye for the seasoned microcontroller programmer. For this to work reasonably I had to introduce one new first degree keyword (BIT) and three second degree keywords (SET, CLEAR and TOGGLE). Plov018 accepts the following source:
PROGRAM test31 CONSTANTS Ser0 = 101 Ser1 = 105 DTR0 = 102 DTR1 = 118 wdt = 5 END VARIABLES a b cc ddd END BEGIN BIT SET Ser0 wdt + 1 BIT CLEAR 1001 7 BIT TOGGLE ddd wdt END test31The general syntax is
BIT <operation> port bitThe operation is one of
Plov018 : the source
Below are the changes and additions. First one new errormessage:
35 : InOut.WriteString ("SET, CLEAR or TOGGLE expected")
Next the addition to StatementSequence:
ELSIF Strings.StrEq (token, "BIT") THEN isBitThen the actual implementation procedure:
PROCEDURE isBit;
BEGIN
GetSymbol;
IF Strings.StrEq (token, "SET") THEN
GetSymbol;
Expression;
Expression;
CG ("SET-BIT");
CG ("")
ELSIF Strings.StrEq (token, "CLEAR") THEN
GetSymbol;
Expression;
Expression;
CG ("CLEAR-BIT");
CG ("")
ELSIF Strings.StrEq (token, "TOGGLE") THEN
GetSymbol;
Expression;
Expression;
CG ("TOGGLE-BIT");
CG ("")
ELSE
ErrorMessage (35);
Skip2LF;
GetSymbol
END
END isBit;
And last, the addition to Init:
IF StoreSymbol ("BIT") = FALSE THEN ErrorMessage (0) END;
BIT must be in the symbol table with the attribute 'Keyword' since it is part of StatementSequence.
Plov018 : see it run
Here is the test program:
PROGRAM test31 CONSTANTS Const = 101 Ser1 = 105 DTR0 = 102 DTR1 = 118 wdt = 5 END VARIABLES var1 var2 var3 END BEGIN BIT SET Const var3 BIT TOGLE var1 wdt BIT CLEAR 1001 7 END test31And this is what the console looks like after compiling:
PROGRAM test31 CONSTANTS Const = 101 Ser1 = 105 DTR0 = 102 DTR1 = 118 wdt = 5 END VARIABLES var1 var2 var3 END BEGIN BIT SET Const var3 BIT TOGLE @@ -- SET, CLEAR or TOGGLE expected in line 14 var1 wdt BIT CLEAR 1001 7 END test31 1 errors found.An error in one of my sources. That's a new experience. Let's try to fix the missing 'G' in 'TOGGLE' and run it again:
PROGRAM test31 CONSTANTS Const = 101 Ser1 = 105 DTR0 = 102 DTR1 = 118 wdt = 5 END VARIABLES var1 var2 var3 END BEGIN BIT SET Const var3 BIT TOGGLE var1 wdt BIT CLEAR 1001 7 END test31 No errors found.That's more like it! Now let's have a look at the PALO source:
# PROGRAM test31 VARIABLE var1 VARIABLE var2 VARIABLE var3 LABEL MAINLOOP STORE 101 FETCH var3 SET-BIT FETCH var1 STORE 5 TOGGLE-BIT STORE 1001 STORE 7 CLEAR-BIT LABEL EXITMAINLOOP # Done #
Plov018 : what's next?
Next. I think I won't be able to postpone it any longer. Next will be a first attempt on an ALTO (i.e. a code generator) for the ATmega128 MCU (MicroController Unit). Look in the ETT section to see the hardware that ultimately will be used as the target system.
Plov019 will not be made. The next release will start with Plov020 and it will mainly be fixes and changes to
make the ALTO backend run smoother, if any. At this moment, I am still struggling with the concept of the
index register. Most MCU's have several index registers so arbitrary cells in RAM or EEPROM can be addresses
and acted upon. I'm not sure how to deal with this.
Yet, I have no choice than implementing it. It is this, or start thinking about array parameters. And that's
just one bridge too far, for the time being.
Page created on 3 October 2008 and
Page equipped with FroogleBuster technology