Both sides previous revision
Previous revision
Next revision
|
Previous revision
|
manual:chapter5:asm [2019/12/03 15:50] claudio [Flow control] |
manual:chapter5:asm [2021/09/29 05:58] (current) jojo1973 [Simple assignments with operators] |
In these cases a compact subset of instructions, with a different syntax and based on the manipulation of a small number of global registers, may achieve greater clarity; this subset of the language, given its compact format, is called **Assembly-like Instruction Set**. | In these cases a compact subset of instructions, with a different syntax and based on the manipulation of a small number of global registers, may achieve greater clarity; this subset of the language, given its compact format, is called **Assembly-like Instruction Set**. |
| |
The Assembly-like Instruction Set is not meant as a separate programming language neither its feature are intended to be sandboxed in exclusive environments: its statements can be freely intermingled with **newRPL** commands and to suit anyone's programming style. | The Assembly-like Instruction Set is not meant as a separate programming language neither its features are intended to be sandboxed in exclusive environments: its statements can be freely intermingled with **newRPL** commands to suit anyone's programming style. |
| |
==== Registers and pseudo-registers ==== | ==== Registers and pseudo-registers ==== |
| ::: | ::: | ''ASIN'' | ::: | ::: | ''MAX'' | | | ::: | ::: | ''ASIN'' | ::: | ::: | ''MAX'' | |
| ::: | ::: | ''ACOS'' | ::: | ::: | ''RND'' | | | ::: | ::: | ''ACOS'' | ::: | ::: | ''RND'' | |
| ::: | ::: | ''ATAN'' | ::: | ::: | | | | ::: | ::: | ''ATAN'' | ::: | ::: | ''CLR'' | |
| ::: | ::: | ''SINH'' | ::: | ::: | ::: | | | ::: | ::: | ''SINH'' | ::: | ::: | | |
| ::: | ::: | ''COSH'' | ::: | ::: | ::: | | | ::: | ::: | ''COSH'' | ::: | ::: | | |
| ::: | ::: | ''TANH'' | ::: | ::: | ::: | | | ::: | ::: | ''TANH'' | ::: | ::: | ::: | |
| ::: | ::: | ''ASINH'' | ::: | ::: | ::: | | | ::: | ::: | ''ASINH'' | ::: | ::: | ::: | |
| |
| '':A=B+#1'' | Add ''1'' to the value of register ''B'' and assign the result to register ''A'' | | | '':A=B+#1'' | Add ''1'' to the value of register ''B'' and assign the result to register ''A'' | |
| '':E=R { 1 2 3 }'' | Assign the list ''{ 1 2 3 }'' to register ''E'' | | | '':E=R { 1 2 3 }'' | Store the list ''{ 1 2 3 }'' in register ''E'' | |
| '':P=A'' | Push the value of register ''A'' to the stack | | | '':P=A'' | Push the value of register ''A'' to the stack | |
| '':A=S2'' '':S2=S1'' '':S1=A'' | Swap stack level 1 with level 2 using register ''A'' as temporary storage. An error is raised if the stack contains less than 2 levels | | | '':A=S2'' '':S2=S1'' '':S1=A'' | Swap stack level 1 with level 2 using register ''A'' as temporary storage. An error is raised if the stack contains less than 2 levels | |
| '':C+=B^#2'' | Square the value register ''B'' and adds the result to register ''C'' | | | '':C+=B^#2'' | Square the value register ''B'' and adds the result to register ''C'' | |
| | '':B=R^#2 π'' | Assign ''%%'%%π^2%%'%%'' to register B. This example shows that register ''R'' must not necessarily be the second argument of a binary operator | |
| |
==== Assignment with math functions ==== | ==== Assignment with math functions ==== |
| ''AL'' | Always | --- | --- | | | ''AL'' | Always | --- | --- | |
| ''LT'' | Less Than | --- | Set | | | ''LT'' | Less Than | --- | Set | |
| ''EQ'' | Equals | Set | --- | | | ''EQ'' or ''Z'' | Equals | Set | --- | |
| ''LE'' | Less Than or Equals | --- | Set | | | ''LE'' | Less Than or Equals | --- | Set | |
| ::: | ::: | Set | --- | | | ::: | ::: | Set | --- | |
| ''NA'' | Never | --- | --- | | | ''NA'' | Never | --- | --- | |
| ''GE'' | Greater Than or Equals | --- | Clear | | | ''GE'' | Greater Than or Equals | --- | Clear | |
| ''NE'' | Not Equals | Clear | --- | | | ''NE'' or ''NZ'' | Not Equals | Clear | --- | |
| ''GT'' | Greater Than | Clear | Clear | | | ''GT'' | Greater Than | Clear | Clear | |
| |
| '':PUSH.A.#3'' | Reverse of '':POP''. In this example will do '':P=C'', '':P=B'' and '':P=A'' | | | '':PUSH.A.#3'' | Reverse of '':POP''. In this example will do '':P=C'', '':P=B'' and '':P=A'' | |
| '':RPUSH.A.#3'' | Reverse of '':RPOP''. In this example will do '':P=A'', '':P=B'', and '':P=C'' | | | '':RPUSH.A.#3'' | Reverse of '':RPOP''. In this example will do '':P=A'', '':P=B'', and '':P=C'' | |
| | '':CLR.A.#3'' | Set registers to zero (clear) starting with ''A'', and as many registers as requested. In this example will do '':A=0'', '':B=0'' and '':C=0'' | |
| |
==== Example code ==== | ==== Example code ==== |
-103 SF @ Complex results | -103 SF @ Complex results |
:A=RPOP.S1.#3 @ Store coefficients in registers | :A=RPOP.S1.#3 @ Store coefficients in registers |
:CMP.A.#0 :FPUSH.EQ @ a=0? Push test on the stack | :AND.A.C @ Are either zero? |
:CMP.C.#0 :FPUSH.EQ @ c=0? Push test on the stack | :SKIP.NZ @ Skip next seco if both A and C were non-zero |
OR @ Are either zero? | |
:CMP.S1.#1 DROP @ Turn newRPL boolean into flags and discard it | |
:SKIP.NE @ Skip next seco if false | |
:: "Zero Input Invalid" | :: "Zero Input Invalid" |
DOERR @ Abort with error | DOERR @ Abort with error |
; | ; |
:P=#0-B @ Push -B on stack | :D=#0-B @ -B |
DUP SQ @ -B, B^2 | :E=B*B @ B^2 |
4 :S1*=A :S1*=C @ -B, B^2, 4*A*C | :F=#4*A :F*=C @ 4*A*C |
- √ @ -B, √(B^2-4*A*C) | :E-=F :E=SQRT.E @ √(B^2-4*A*C) |
:P=B SIGN * - @ -B-SIGN(B)*√(B^2-4*A*C) | |
2 / :S1/=A @ (-B-SIGN(B)*√(B^2-4*A*C))/2/A is R1, the largest root in absolute value | :CMP.B.#0 |
:P=C :S1/=A @ R1, C/A | :SKIP.GE :F=D+E @ -B+√(B^2-4*A*C) when B<=0 |
| :SKIP.LT :F=D-E @ -B-√(B^2-4*A*C) when B>0 |
| |
| :E=A*#2 @ 2*A |
| :P=F/E @ (-B-SIGN(B)*√(B^2-4*A*C))/2/A is R1, the largest root in absolute value |
| :P=C/A @ R1, C/A |
:S1/=S2 @ C/(R1*A) is R2, the other root | :S1/=S2 @ C/(R1*A) is R2, the other root |
» | » |
:F*=A @ F='(y2-y1)*(X-x1)' | :F*=A @ F='(y2-y1)*(X-x1)' |
:B-=F @ B='(Y-y1)*(x2-x1)-(y2-y1)*(X-x1)' | :B-=F @ B='(Y-y1)*(x2-x1)-(y2-y1)*(X-x1)' |
:PUSH.B.#1 @ Push result on the stack | :P=B @ Push result on the stack |
» | » |
» | » |
</code> | </code> |