mirror of
https://github.com/Russell-S-Harper/COMMON.git
synced 2024-11-28 05:51:09 +00:00
54 lines
654 B
Plaintext
54 lines
654 B
Plaintext
#include "rom.h"
|
|
#include "macros.h"
|
|
#include "globals.h"
|
|
|
|
* = $300 ; any address outside of page zero is okay because all code is relocatable
|
|
|
|
CODE(DEMO)
|
|
|
|
START
|
|
CMN
|
|
SET(R0, 9.4662)
|
|
SET(R1, SQRT2)
|
|
LDI(R7, R1)
|
|
MUL(R7, R7, R7)
|
|
PSH(R0)
|
|
BRS(FACTORIAL)
|
|
POP(R4)
|
|
SET(R5, E)
|
|
LDI(R6, R5)
|
|
SET(R1, ZERO)
|
|
INR(R1)
|
|
SVI(R1, R6)
|
|
LDI(R0, R1)
|
|
ESC
|
|
BRK
|
|
|
|
BEGIN(FACTORIAL)
|
|
POP(R1)
|
|
SET(R2, 1)
|
|
MOD(R3, R1, R2)
|
|
SUB(R1, R1, R3)
|
|
_1 TST(R1)
|
|
BRZ(_2)
|
|
MUL(R2, R2, R1)
|
|
DCR(R1)
|
|
BRA(_1)
|
|
_2 PSH(R2)
|
|
RTN
|
|
END(FACTORIAL)
|
|
|
|
END(DEMO)
|
|
|
|
DATA(_)
|
|
|
|
; preset constants
|
|
DEFINE(PI, 3.14159)
|
|
DEFINE(E, 2.71828)
|
|
DEFINE(SQRT2, 1.41421)
|
|
|
|
; working space
|
|
RESERVE(2)
|
|
|
|
END(_)
|