manual:chapter5:asm

This is an old revision of the document!


Registers and pseudo-registers

There are 8 global and persistent registers, named A through H, free for the users to assign any object to them.

There's 7 pseudo-registers that correspond to the stack levels: S1 through S7.

Finally there's 2 additional pseudo-registers P and R. P pushes a result to the stack, and it is used only as a destination register, not as an argument. R is a reference to the next object in the executing program. R cannot be used as a destination.

Instruction syntax

Asm instructions always must start with colon : and may not have any spaces. Wherever a separator is needed, use the dot ..

Statements always have:

  • An optional destination (A-H, S1-S7 or P)
  • An optional assignment operator (=, +=, -=, *= or /=)
  • An operator or command (+,-,*,/,^ as operators, or other commands as listed below)
  • One or 2 arguments to the operator or command. Arguments can be a register or reference (A-H, S1-S7 or R), or an integer number in the range 0-15.

Examples:

a) Simple assignments with operators:

:A=B+1 Adds one to the register B and assigns the result to A.

:P=A Pushes the register A to the stack

:A=S2 :S2=S1 :S1=A Equivalent to SWAP

:C+=B^2 Squares B, adds the result to C

b) Assignment with math functions or commands

:A+=ABS.S1 Adds ABS(Stack level 1) to the value of A.

:C*=SIN.A Compute SIN(A) and multiply with the content of C.

c) Comparison

:CMP.A.B Compares A and B and sets internal flags

d) Flow control

:SKIP.EQ Skip next instruction if result of last comparison was Equal. Other possible comparison results are LT (less than), LTE (less than or equal), GT (greater than), GTE (greater than or equal), or NE (not equal)

:LOOP.EQ Must be followed by a program or secondary « … » or :: … ;. It will repeat the secondary while the result of the last comparison matches, see :SKIP for other comparisons. Notice the program that follows MUST update the internal flags with a :CMP.x.y type instruction or it will loop indefintely.

:FPUSH.EQ Pushes True (1) to the stack if the result of the last comparison matches (see :SKIP for other comparisons), otherwise pushes False (0) to the stack. This is useful to combine standard RPL flow control structures « IF :CMP.A.0 :FPUSH.EQ THEN … END ».

e) Stack helpers

:A=POP.S1.3 Remove values from the stack (pop) from the given stack levels and store the values on registers A, B, C… starting with A, and as many values as needed. The first argument refers to a stack level (1 to current stack depth), and can be given as a literal number, as another register containing an integer number object or reference to the actual stack level (S1 as used in this example). The second arguments refers to the number of items to pop, and in a similar way, it can be given as a literal number (3 in this example), a register or reference to an integer number object. The example given will assign :A=S1, :B=S2 and :C=S3, while also removing the values from the stack.

:A=RPOP.S1.3 Similar to :POP but the assignment is done in reverse order. In this example :A=S3, :B=S2, and :C=S1.

:PUSH.A.3 Reverse of :POP, this example will do :P=C, :P=B and :P=A

:RPUSH.A.3 Reverse of :RPOP, this example will do :P=A, :P=B, and :P=C

  • manual/chapter5/asm.1574204672.txt.gz
  • Last modified: 2019/11/19 15:04
  • by claudio