next up previous contents
Next: Binary Operators Up: Expressions Previous: Variable Values

Unary Operators

Unary operators operate on one value. In Pascal there are two of these operators, the negation operator ` -' and the not operator. For each of these operators the value to be operated on has to be on top of the operand stack.

To negate ` -' a value of Pascal type integer or real you use respectively the instructions ineg and fneg.

To do the Pascal not operation, there is no JVM instruction, so it has to be done by hand. To do a not you check if the value on the operand stack is equal to 0, if so you push a 1 in its place and a 0 if it is not.

This is done by the following sequence of instructions:

 
 ifeq 7     		 if equal to 0, jump 7 bytes (skipping next 2
			   instructions);

iconst_0 not equal to 0, load a 0 on the stack;

goto 4 jump 4 bytes further (after the next instruction);

iconst_1 load a 1 on the stack.

Every branch instruction, like the ifeq and goto instructions here, take byte offsets as operands. All the instructions and all their operands are one byte each. See section 4.2 for the number of operands for each instruction.



mark@bottom.xs4all.nl