PCalc Description

3
Introduction PCalc is simple programmer calculator with stack instructions. It allows you to create, edit, run and debug simple programs. PCalc program consists of one or more functions. Functions can be nested (as in Pascal). Code written outside the body of any function is considered to belong to main function. Each function may have local variables. Also program may have input parameters which should be specified before starting execution of the program. Result of program execution can be placed in stack or in local variables. Instruction set PCalc implements simple stack machine. Operands of each instruction should be pushed on operand's stack before execution of the operation. When operation is executed, it pops it arguments from stack and result of operation is pushed on the stack. Stack can be also used to path data to called functions and get results of execution of thus function. PCalc instructions can be grouped in several units: load/store, operators, functions and flow control: Load/Store Command Parameter Operands Description LITERAL Constant value 0 Push immediate constant to the stack LOAD Variable name 0 Push value of local variable to the stack INPUT Input parameter name 0 Push value of input parameter to the stack STORE Variable name 1 Pop value from the stack and store it in local variable DUP - 1 Duplicate top stack element SWAP - 2 Swap two values on the top of the stack LOAD_E - 0 Push E constant to the stack LOAD_PI - 0 Push PI constant to the stack Operators Command Operands Description NEG 1 Negative value ADD 2 Add two operands SUB 2 Subtract two operands MUL 2 Multiply two operands DIV 2 Divide two operands EQ 2 Check if operands are equal NE 2 Check if operands are not equal GT 2 Check if first operand is greater than second GE 2 Check if first operand is greater or equal than second LT 2 Check if first operand is less than second LE 2 Check if first operand is less or equal than second Functions Strona 1 z 3 Programming calculator 2008-02-01 http://www.garret.ru/~knizhnik/PCalc.html

description

Operating manual for PCalc - a programmable calculator

Transcript of PCalc Description

Page 1: PCalc Description

Introduction

PCalc is simple programmer calculator with stack instructions. It allows you to create, edit, run and debug simple programs. PCalc program consists of one or more functions. Functions can be nested

(as in Pascal). Code written outside the body of any function is considered to belong to main function. Each function may have local variables. Also program may have input parameters which should be specified before starting execution of the program. Result of program execution can be

placed in stack or in local variables.

Instruction set

PCalc implements simple stack machine. Operands of each instruction should be pushed on

operand's stack before execution of the operation. When operation is executed, it pops it arguments from stack and result of operation is pushed on the stack. Stack can be also used to path data to called functions and get results of execution of thus function. PCalc instructions can be grouped in

several units: load/store, operators, functions and flow control:

Load/Store

Command Parameter Operands Description

LITERAL Constant value 0 Push immediate constant to the stack

LOAD Variable name 0 Push value of local variable to the stack

INPUT Input parameter name

0 Push value of input parameter to the stack

STORE Variable name 1Pop value from the stack and store it in local variable

DUP - 1 Duplicate top stack element

SWAP - 2 Swap two values on the top of the stack

LOAD_E - 0 Push E constant to the stack

LOAD_PI - 0 Push PI constant to the stack

Operators

Command Operands Description

NEG 1 Negative value

ADD 2 Add two operands

SUB 2 Subtract two operands

MUL 2 Multiply two operands

DIV 2 Divide two operands

EQ 2 Check if operands are equal

NE 2 Check if operands are not equal

GT 2 Check if first operand is greater than second

GE 2 Check if first operand is greater or equal than second

LT 2 Check if first operand is less than second

LE 2 Check if first operand is less or equal than second

Functions

Strona 1 z 3Programming calculator

2008-02-01http://www.garret.ru/~knizhnik/PCalc.html

Page 2: PCalc Description

PCalc development environment

Main menu

PCalc can store several programs. The program is saved each time you try to execute it or exit the application. The main menu allows you to select program from the list and either edit, either run, either debug the program (execute program step-by-step). Also it is possible to create new program

or delete existing program and undo the last delete operation (undo is possible until you exit the application).

Edit program menu

Function Operands Description

ABS 1 Absolute value

ACOS 1 Arc cosine

ASIN 1 Arc sine

ATAN 1 Arc tangent

ATAN2 2the theta component of the point in polar coordinates corresponds to the point Cartesian coordinates specified by function operands.

CEIL 1 Smallest integer value which is not less than operand

COS 1 Cosine

EXP 1 Exponent

CEIL 1 Largest integer value which is not greater than operand

FRAC 1 Fraction part of the operand value

INT 1 Integer part of the operand value

LOG 1 Natural logarithm

LOG10 1 Logarithm with base 10

MAX 2 Maximum of two operand values

MIN 2 Minimum of two operand values

POW 2 Raise first operand to the power specified by second operand

RND 0 Generate random number in range [0,1)

ROUND 1 Round operand to the closest integer value

SIN 1 Sine

SQRT 1 Square root

TAN 1 Tangent

Control flow

Function Parameter Operands Description

IF Label 1Pop value from top of stack and if it is zero, then transfer control to the specified label

CALLFunction

name 0

Call specified function. Function can access operands in the

operands stack and push return value also to the stack

RETURN none 0 Return from the function

IF Label 0 Transfer control to the specified label

Strona 2 z 3Programming calculator

2008-02-01http://www.garret.ru/~knizhnik/PCalc.html

Page 3: PCalc Description

When you create new program or edit existing one, you will see code of main function. Use Insert

command to add new instruction. To add instruction, you should first select group of instructions and then choose particular instruction in the group. If instruction requires additional information (name of variable, immediate constant,...), then special input dialog will be started. For local variables and

program parameters you can either select one of the existed names or add new name. It is possible to delete instructions using Delete command.

It is possible to move the label from one instruction to another. First you should position cursor on the instruction with label, then execute Move command. You then will be asked to select instruction

to which label should be moved. Obviously, all transfers to the original instruction referencing this label will now be redirected to new location.

You can get list of all subfunctions of the current function execute Functions command. Selecting function from the list will open edit dialogue for specified function. Nested function can access local

variables of the outer functions.

To get list of all visible local variables execute Variables. It will print list of all local variables

declared in this and containing functions. It is possible to rename or delete variable (only variables of the self function can be renamed or deleted). Attempt to delete used variable will be rejected.

Run program menu

Run program form first ask you to enter values of the program input parameters (if any) and then start program execution. Elapsed program execution time is displayed at the screen. It is possible to

stop the program using Stop command, in this case debugger is activated.

When the program is terminated, it is possible to inspect results of execution. Results of execution can be either stored in stack, either in local variables of main function. Content of the stack is dumped. And to see values of particular local variables of main function use Variables command.

Using Restart command it is possible to rerun the program (with new values of parameters).

Debug program menu

Debugger is activated when you start program in debug mode or when you stop execution of the program. In debugger it is possible to execute program step-by-step, inspecting content of stack and

local variables. Stack command can be used to dump the operands stack, Variables command - to inspect values of local variables and Trace command - to see back trace (function call stack).

At any moment you can continue normal execution of the program or restart it.

Strona 3 z 3Programming calculator

2008-02-01http://www.garret.ru/~knizhnik/PCalc.html