Archive for category HP-48G

Variable Declaration

Let’s continue our HP-48 programming course, this time I’m going talk about variable declaration. A variable is where data is stored temporally, therefore programs can process them. In USER-RPL language,  you can local, global or environment variables.

Local variables

Programs use this kind of variables in order to do internal operations. Let’s see an example:

HP48 -  local variables - en

Here, variables  ONE and TWO have the values 1 and 2 respectively. Later, inside the program they are used to perform an addition which answer is left on the calculator’s stack.

Global variables

If you define a global variable, it can be used in the current program and it can also be used by other programs that were invoked from the current one. I modified the latter example to use an external program which perform the addition, called PLUS:

HP48 -  global variables - en

The PLUS program invokes global variables and performs the addition, as is showed in here:

HP48 - global variables2 -en

This kind of declaration has no limit on variable’s scope, because it’s defined as global. But it has a downside effect: programs that use that type of declaration will be be bigger than those which not.

Environment variables

The environment variables are the ones you can use from the current working directory. For instance, values 1 and 2 can be stored in the current directory using ONE and TWO as named, and you can edit the PLUS program to use these variables:

HP48 - environment variables -en

Este tipo de declaración no tiene restricción en el ámbito de existencia de la variable, ya que es definida como global. Pero tiene como inconveniente que los programas que usan variables globales ocupan más espacio que los que no lo usan.


2 Comments