# Oppolzer - Informatik / Stanford Pascal Compiler

Home       Lebenslauf       Schwerpunkte       Kenntnisse       Seminare       Kunden       Projekte       Produkte       Blog       Stanford Pascal       Kontakt

## The Stanford Pascal Compiler / Evolution Steps

Back to Compiler main page

### Bit operations

Since December 2016, the further development of the Pascal compiler has become much easier, because now changes to the compiler (first pass) and tests can be done all at the Windows platform. "Ports" to Hercules and VM only need to be done, if changes to the PRR format or extensions to the P-Code translator are needed, and at a very late stage. Not all changes or extensions to the compiler require extensions to the P-Code.

From some discussions on the FPC mailing list, I got the idea to support bit operations on integer operands, too.

The operations AND, OR, NOT have been extended to do bit operations, when being used with integers (an error 134 was issued before, if these "logical" operations were used with integer operands).

Another operation XOR is provided (a new reserved symbol) for exclusive or operation; it can be used with integer or boolean operands.

A new P-Code instruction XOR has been created; the P-Code instructions AND, IOR, NOT and XOR now have a type parameter, which can be B for boolean or I for integer. B defines the (old) logical operation, I is for bit operations (on integers).

Sample program:

 ``` program TESTAND ( OUTPUT ) ; (********) (*\$A+ *) (********) var X , Y : INTEGER ; A , B : BOOLEAN ; begin (* HAUPTPROGRAMM *) X := 0X0E ; Y := 0X1D ; A := FALSE ; B := TRUE ; WRITELN ( 'x ' , X ) ; WRITELN ( 'y ' , Y ) ; WRITELN ( 'x and y ' , X and Y ) ; WRITELN ( 'x and y ' , X & Y ) ; WRITELN ( 'x or y ' , X or Y ) ; WRITELN ( 'x or y ' , X | Y ) ; WRITELN ( 'x xor y ' , X xor Y ) ; WRITELN ( 'not x ' , not X ) ; WRITELN ( 'not y ' , not Y ) ; WRITELN ( 'a ' , A ) ; WRITELN ( 'b ' , B ) ; WRITELN ( 'a and b ' , A and B ) ; WRITELN ( 'a and b ' , A & B ) ; WRITELN ( 'a or b ' , A or B ) ; WRITELN ( 'a or b ' , A | B ) ; WRITELN ( 'a xor b ' , A xor B ) ; WRITELN ( 'not a ' , not A ) ; WRITELN ( 'not b ' , not B ) ; end (* HAUPTPROGRAMM *) . ```

You may notice the integer constants in hexadecimal notation, which were introduced with this change, too.

The output of the sample program:

 ``` x 14 y 29 x and y 12 x and y 12 x or y 31 x or y 31 x xor y 19 not x -15 not y -30 a FALSE b TRUE a and b FALSE a and b FALSE a or b TRUE a or b TRUE a xor b TRUE not a TRUE not b FALSE ```

