(math32.tal) Removed globals
This commit is contained in:
parent
b5669a52be
commit
51c422c9cb
|
@ -54,9 +54,6 @@
|
||||||
( - mul32 memory, 12 bytes )
|
( - mul32 memory, 12 bytes )
|
||||||
( - _divmod32 memory, 16 bytes )
|
( - _divmod32 memory, 16 bytes )
|
||||||
|
|
||||||
%DEBUG { #ff #0e DEO }
|
|
||||||
%RTN { JMP2r }
|
|
||||||
%TOR { ROT ROT } ( a b c -> c a b )
|
|
||||||
%COMPLEMENT32 { SWP2 #ffff EOR2 SWP2 #ffff EOR2 }
|
%COMPLEMENT32 { SWP2 #ffff EOR2 SWP2 #ffff EOR2 }
|
||||||
%DUP4 { OVR2 OVR2 }
|
%DUP4 { OVR2 OVR2 }
|
||||||
%POP4 { POP2 POP2 }
|
%POP4 { POP2 POP2 }
|
||||||
|
@ -74,7 +71,7 @@
|
||||||
,&loop JMP
|
,&loop JMP
|
||||||
&done
|
&done
|
||||||
POP ( n )
|
POP ( n )
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
@bitcount16 ( x* -> n^ )
|
@bitcount16 ( x* -> n^ )
|
||||||
SWP ( xlo xhi )
|
SWP ( xlo xhi )
|
||||||
|
@ -82,40 +79,40 @@
|
||||||
DUP #00 NEQ ( xlo nhi nhi!=0 )
|
DUP #00 NEQ ( xlo nhi nhi!=0 )
|
||||||
,&hi-set JCN ( xlo nhi )
|
,&hi-set JCN ( xlo nhi )
|
||||||
SWP ;bitcount8 JSR2 ADD ( nhi+nlo )
|
SWP ;bitcount8 JSR2 ADD ( nhi+nlo )
|
||||||
RTN
|
JMP2r
|
||||||
&hi-set
|
&hi-set
|
||||||
SWP POP #08 ADD ( nhi+8 )
|
SWP POP #08 ADD ( nhi+8 )
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
@bitcount32 ( x** -> n^ )
|
@bitcount32 ( x** -> n^ )
|
||||||
SWP2 ( xlo* xhi* )
|
SWP2 ( xlo* xhi* )
|
||||||
;bitcount16 JSR2 ( xlo* nhi )
|
;bitcount16 JSR2 ( xlo* nhi )
|
||||||
DUP #00 NEQ ( xlo* nhi nhi!=0 )
|
DUP #00 NEQ ( xlo* nhi nhi!=0 )
|
||||||
,&hi-set JCN ( xlo* nhi )
|
,&hi-set JCN ( xlo* nhi )
|
||||||
TOR ;bitcount16 JSR2 ADD RTN ( nhi+nlo )
|
ROT ROT ;bitcount16 JSR2 ADD JMP2r ( nhi+nlo )
|
||||||
&hi-set
|
&hi-set
|
||||||
TOR POP2 #10 ADD ( nhi+16 )
|
ROT ROT POP2 #10 ADD ( nhi+16 )
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( equality )
|
( equality )
|
||||||
|
|
||||||
( x == y )
|
( x == y )
|
||||||
@eq32 ( xhi* xlo* yhi* ylo* -> bool^ )
|
@eq32 ( xhi* xlo* yhi* ylo* -> bool^ )
|
||||||
ROT2 EQU2 STH
|
ROT2 EQU2 STH
|
||||||
EQU2 STHr AND RTN
|
EQU2 STHr AND JMP2r
|
||||||
|
|
||||||
( x != y )
|
( x != y )
|
||||||
@ne32 ( xhi* xlo* yhi* ylo* -> bool^ )
|
@ne32 ( xhi* xlo* yhi* ylo* -> bool^ )
|
||||||
ROT2 NEQ2 STH
|
ROT2 NEQ2 STH
|
||||||
NEQ2 STHr ORA RTN
|
NEQ2 STHr ORA JMP2r
|
||||||
|
|
||||||
( x == 0 )
|
( x == 0 )
|
||||||
@is-zero32 ( x** -> bool^ )
|
@is-zero32 ( x** -> bool^ )
|
||||||
ORA2 #0000 EQU2 RTN
|
ORA2 #0000 EQU2 JMP2r
|
||||||
|
|
||||||
( x != 0 )
|
( x != 0 )
|
||||||
@non-zero32 ( x** -> bool^ )
|
@non-zero32 ( x** -> bool^ )
|
||||||
ORA2 #0000 NEQ2 RTN
|
ORA2 #0000 NEQ2 JMP2r
|
||||||
|
|
||||||
( comparisons )
|
( comparisons )
|
||||||
|
|
||||||
|
@ -123,58 +120,58 @@
|
||||||
@lt32 ( x** y** -> bool^ )
|
@lt32 ( x** y** -> bool^ )
|
||||||
ROT2 SWP2 ( xhi yhi xlo ylo )
|
ROT2 SWP2 ( xhi yhi xlo ylo )
|
||||||
LTH2 ,<-lo JCN ( xhi yhi )
|
LTH2 ,<-lo JCN ( xhi yhi )
|
||||||
LTH2 RTN
|
LTH2 JMP2r
|
||||||
<-lo
|
<-lo
|
||||||
GTH2 #00 EQU RTN
|
GTH2 #00 EQU JMP2r
|
||||||
|
|
||||||
( x <= y )
|
( x <= y )
|
||||||
@lteq32 ( x** y** -> bool^ )
|
@lteq32 ( x** y** -> bool^ )
|
||||||
ROT2 SWP2 ( xhi yhi xlo ylo )
|
ROT2 SWP2 ( xhi yhi xlo ylo )
|
||||||
GTH2 ,>-lo JCN ( xhi yhi )
|
GTH2 ,>-lo JCN ( xhi yhi )
|
||||||
GTH2 #00 EQU RTN
|
GTH2 #00 EQU JMP2r
|
||||||
>-lo
|
>-lo
|
||||||
LTH2 RTN
|
LTH2 JMP2r
|
||||||
|
|
||||||
( x > y )
|
( x > y )
|
||||||
@gt32 ( x** y** -> bool^ )
|
@gt32 ( x** y** -> bool^ )
|
||||||
ROT2 SWP2 ( xhi yhi xlo ylo )
|
ROT2 SWP2 ( xhi yhi xlo ylo )
|
||||||
GTH2 ,>-lo JCN ( xhi yhi )
|
GTH2 ,>-lo JCN ( xhi yhi )
|
||||||
GTH2 RTN
|
GTH2 JMP2r
|
||||||
>-lo
|
>-lo
|
||||||
LTH2 #00 EQU RTN
|
LTH2 #00 EQU JMP2r
|
||||||
|
|
||||||
( x > y )
|
( x > y )
|
||||||
@gteq32 ( x** y** -> bool^ )
|
@gteq32 ( x** y** -> bool^ )
|
||||||
ROT2 SWP2 ( xhi yhi xlo ylo )
|
ROT2 SWP2 ( xhi yhi xlo ylo )
|
||||||
LTH2 ,<-lo JCN ( xhi yhi )
|
LTH2 ,<-lo JCN ( xhi yhi )
|
||||||
LTH2 #00 EQU RTN
|
LTH2 #00 EQU JMP2r
|
||||||
<-lo
|
<-lo
|
||||||
GTH2 RTN
|
GTH2 JMP2r
|
||||||
|
|
||||||
( bitwise operations )
|
( bitwise operations )
|
||||||
|
|
||||||
( x & y )
|
( x & y )
|
||||||
@and32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* )
|
@and32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* )
|
||||||
ROT2 AND2 STH2 AND2 STH2r RTN
|
ROT2 AND2 STH2 AND2 STH2r JMP2r
|
||||||
|
|
||||||
( x | y )
|
( x | y )
|
||||||
@or32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* )
|
@or32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* )
|
||||||
ROT2 ORA2 STH2 ORA2 STH2r RTN
|
ROT2 ORA2 STH2 ORA2 STH2r JMP2r
|
||||||
|
|
||||||
( x ^ y )
|
( x ^ y )
|
||||||
@xor32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* )
|
@xor32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* )
|
||||||
ROT2 EOR2 STH2 EOR2 STH2r RTN
|
ROT2 EOR2 STH2 EOR2 STH2r JMP2r
|
||||||
|
|
||||||
( ~x )
|
( ~x )
|
||||||
@complement32 ( x** -> ~x** )
|
@complement32 ( x** -> ~x** )
|
||||||
COMPLEMENT32 RTN
|
COMPLEMENT32 JMP2r
|
||||||
|
|
||||||
( temporary registers )
|
( temporary registers )
|
||||||
( shared by most operations, except mul32 and div32 )
|
( shared by most operations, except mul32 and div32 )
|
||||||
[ @x0 $1 @x1 $1 @x2 $1 @x3 $1
|
@m32 [ &x0 $1 &x1 $1 &x2 $1 &x3 $1
|
||||||
@y0 $1 @y1 $1 @y2 $1 @y3 $1
|
&y0 $1 &y1 $1 &y2 $1 &y3 $1
|
||||||
@z0 $1 @z1 $1 @z2 $1 @z3 $1
|
&z0 $1 &z1 $1 &z2 $1 &z3 $1
|
||||||
@w0 $1 @w1 $1 @w2 $2 ]
|
&w0 $1 &w1 $1 &w2 $2 ]
|
||||||
|
|
||||||
( bit shifting )
|
( bit shifting )
|
||||||
|
|
||||||
|
@ -184,40 +181,40 @@
|
||||||
DUP #10 LTH ;rshift32-1 JCN2 ( x n )
|
DUP #10 LTH ;rshift32-1 JCN2 ( x n )
|
||||||
DUP #18 LTH ;rshift32-2 JCN2 ( x n )
|
DUP #18 LTH ;rshift32-2 JCN2 ( x n )
|
||||||
;rshift32-3 JMP2 ( x n )
|
;rshift32-3 JMP2 ( x n )
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( shift right by 0-7 bits )
|
( shift right by 0-7 bits )
|
||||||
@rshift32-0 ( x** n^ -> x<<n )
|
@rshift32-0 ( x** n^ -> x<<n )
|
||||||
STHk SFT ;z3 STA ( write z3 )
|
STHk SFT ;m32/z3 STA ( write z3 )
|
||||||
#00 STHkr SFT2 #00 ;z3 LDA ORA2 ;z2 STA2 ( write z2,z3 )
|
#00 STHkr SFT2 #00 ;m32/z3 LDA ORA2 ;m32/z2 STA2 ( write z2,z3 )
|
||||||
#00 STHkr SFT2 #00 ;z2 LDA ORA2 ;z1 STA2 ( write z1,z2 )
|
#00 STHkr SFT2 #00 ;m32/z2 LDA ORA2 ;m32/z1 STA2 ( write z1,z2 )
|
||||||
#00 STHr SFT2 #00 ;z1 LDA ORA2 ( compute z0,z1 )
|
#00 STHr SFT2 #00 ;m32/z1 LDA ORA2 ( compute z0,z1 )
|
||||||
;z2 LDA2
|
;m32/z2 LDA2
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( shift right by 8-15 bits )
|
( shift right by 8-15 bits )
|
||||||
@rshift32-1 ( x** n^ -> x<<n )
|
@rshift32-1 ( x** n^ -> x<<n )
|
||||||
#08 SUB STH POP
|
#08 SUB STH POP
|
||||||
STHkr SFT ;z3 STA ( write z3 )
|
STHkr SFT ;m32/z3 STA ( write z3 )
|
||||||
#00 STHkr SFT2 #00 ;z3 LDA ORA2 ;z2 STA2 ( write z2,z3 )
|
#00 STHkr SFT2 #00 ;m32/z3 LDA ORA2 ;m32/z2 STA2 ( write z2,z3 )
|
||||||
#00 STHr SFT2 #00 ;z2 LDA ORA2 ( compute z1,z2 )
|
#00 STHr SFT2 #00 ;m32/z2 LDA ORA2 ( compute z1,z2 )
|
||||||
#00 TOR ;z3 LDA
|
#00 ROT ROT ;m32/z3 LDA
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( shift right by 16-23 bits )
|
( shift right by 16-23 bits )
|
||||||
@rshift32-2 ( x** n^ -> x<<n )
|
@rshift32-2 ( x** n^ -> x<<n )
|
||||||
#10 SUB STH POP2
|
#10 SUB STH POP2
|
||||||
STHkr SFT ;z3 STA ( write z3 )
|
STHkr SFT ;m32/z3 STA ( write z3 )
|
||||||
#00 STHr SFT2 #00 ;z3 LDA ORA2 ( compute z2,z3 )
|
#00 STHr SFT2 #00 ;m32/z3 LDA ORA2 ( compute z2,z3 )
|
||||||
#0000 SWP2
|
#0000 SWP2
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( shift right by 16-23 bits )
|
( shift right by 16-23 bits )
|
||||||
@rshift32-3 ( x** n^ -> x<<n )
|
@rshift32-3 ( x** n^ -> x<<n )
|
||||||
#18 SUB STH POP2 POP ( x0 )
|
#18 SUB STH POP2 POP ( x0 )
|
||||||
#00 SWP #0000 SWP2 ( 00 00 00 x0 )
|
#00 SWP #0000 SWP2 ( 00 00 00 x0 )
|
||||||
STHr SFT
|
STHr SFT
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( x << n )
|
( x << n )
|
||||||
@lshift32 ( x** n^ -> x<<n )
|
@lshift32 ( x** n^ -> x<<n )
|
||||||
|
@ -225,70 +222,70 @@
|
||||||
DUP #10 LTH ;lshift32-1 JCN2 ( x n )
|
DUP #10 LTH ;lshift32-1 JCN2 ( x n )
|
||||||
DUP #18 LTH ;lshift32-2 JCN2 ( x n )
|
DUP #18 LTH ;lshift32-2 JCN2 ( x n )
|
||||||
;lshift32-3 JMP2 ( x n )
|
;lshift32-3 JMP2 ( x n )
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( shift left by 0-7 bits )
|
( shift left by 0-7 bits )
|
||||||
@lshift32-0 ( x** n^ -> x<<n )
|
@lshift32-0 ( x** n^ -> x<<n )
|
||||||
#40 SFT STH ( stash n<<4 )
|
#40 SFT STH ( stash n<<4 )
|
||||||
#00 SWP STHkr SFT2 ;z2 STA2 ( store z2,z3 )
|
#00 SWP STHkr SFT2 ;m32/z2 STA2 ( store z2,z3 )
|
||||||
#00 SWP STHkr SFT2 #00 ;z2 LDA ORA2 ;z1 STA2 ( store z1,z2 )
|
#00 SWP STHkr SFT2 #00 ;m32/z2 LDA ORA2 ;m32/z1 STA2 ( store z1,z2 )
|
||||||
#00 SWP STHkr SFT2 #00 ;z1 LDA ORA2 ;z0 STA2 ( store z0,z1 )
|
#00 SWP STHkr SFT2 #00 ;m32/z1 LDA ORA2 ;m32/z0 STA2 ( store z0,z1 )
|
||||||
STHr SFT ;z0 LDA ORA ( calculate z0 )
|
STHr SFT ;m32/z0 LDA ORA ( calculate z0 )
|
||||||
;z1 LDA ;z2 LDA2
|
;m32/z1 LDA ;m32/z2 LDA2
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( shift left by 8-15 bits )
|
( shift left by 8-15 bits )
|
||||||
@lshift32-1 ( x** n^ -> x<<n )
|
@lshift32-1 ( x** n^ -> x<<n )
|
||||||
#08 SUB #40 SFT STH ( stash [n-8]<<4 )
|
#08 SUB #40 SFT STH ( stash [n-8]<<4 )
|
||||||
#00 SWP STHkr SFT2 ;z1 STA2 ( store z1,z2 )
|
#00 SWP STHkr SFT2 ;m32/z1 STA2 ( store z1,z2 )
|
||||||
#00 SWP STHkr SFT2 #00 ;z1 LDA ORA2 ;z0 STA2 ( store z0,z1 )
|
#00 SWP STHkr SFT2 #00 ;m32/z1 LDA ORA2 ;m32/z0 STA2 ( store z0,z1 )
|
||||||
STHr SFT ;z0 LDA ORA ( calculate z0 )
|
STHr SFT ;m32/z0 LDA ORA ( calculate z0 )
|
||||||
SWP POP ( x0 unused )
|
SWP POP ( x0 unused )
|
||||||
;z1 LDA2 #00
|
;m32/z1 LDA2 #00
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( shift left by 16-23 bits )
|
( shift left by 16-23 bits )
|
||||||
@lshift32-2 ( x** n^ -> x<<n )
|
@lshift32-2 ( x** n^ -> x<<n )
|
||||||
#10 SUB #40 SFT STH ( stash [n-16]<<4 )
|
#10 SUB #40 SFT STH ( stash [n-16]<<4 )
|
||||||
#00 SWP STHkr SFT2 ;z0 STA2 ( store z0,z1 )
|
#00 SWP STHkr SFT2 ;m32/z0 STA2 ( store z0,z1 )
|
||||||
STHr SFT ;z0 LDA ORA ( calculate z0 )
|
STHr SFT ;m32/z0 LDA ORA ( calculate z0 )
|
||||||
STH POP2 STHr
|
STH POP2 STHr
|
||||||
;z1 LDA #0000
|
;m32/z1 LDA #0000
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( shift left by 24-31 bits )
|
( shift left by 24-31 bits )
|
||||||
@lshift32-3 ( x** n^ -> x<<n )
|
@lshift32-3 ( x** n^ -> x<<n )
|
||||||
#18 SUB #40 SFT ( x0 x1 x2 x3 r=[n-24]<<4 )
|
#18 SUB #40 SFT ( x0 x1 x2 x3 r=[n-24]<<4 )
|
||||||
SFT ( x0 x1 x2 x3<<r )
|
SFT ( x0 x1 x2 x3<<r )
|
||||||
SWP2 POP2 SWP POP #0000 #00
|
SWP2 POP2 SWP POP #0000 #00
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( arithmetic )
|
( arithmetic )
|
||||||
|
|
||||||
( x + y )
|
( x + y )
|
||||||
@add32 ( xhi* xlo* yhi* ylo* -> zhi* zlo* )
|
@add32 ( xhi* xlo* yhi* ylo* -> zhi* zlo* )
|
||||||
;y2 STA2 ;y0 STA2 ( save ylo, yhi )
|
;m32/y2 STA2 ;m32/y0 STA2 ( save ylo, yhi )
|
||||||
;x2 STA2 ;x0 STA2 ( save xlo, xhi )
|
;m32/x2 STA2 ;m32/x0 STA2 ( save xlo, xhi )
|
||||||
#0000 #0000 ;z0 STA2 ;z2 STA2 ( reset zhi, zlo )
|
#0000 #0000 ;m32/z0 STA2 ;m32/z2 STA2 ( reset zhi, zlo )
|
||||||
|
|
||||||
( x3 + y3 => z2z3 )
|
( x3 + y3 => z2z3 )
|
||||||
#00 ;x3 LDA #00 ;y3 LDA ADD2 ;z2 STA2
|
#00 ;m32/x3 LDA #00 ;m32/y3 LDA ADD2 ;m32/z2 STA2
|
||||||
|
|
||||||
( x2 + y2 + z2 => z1z2 )
|
( x2 + y2 + z2 => z1z2 )
|
||||||
#00 ;x2 LDA ;z1 LDA2 ADD2 ;z1 STA2
|
#00 ;m32/x2 LDA ;m32/z1 LDA2 ADD2 ;m32/z1 STA2
|
||||||
#00 ;y2 LDA ;z1 LDA2 ADD2 ;z1 STA2
|
#00 ;m32/y2 LDA ;m32/z1 LDA2 ADD2 ;m32/z1 STA2
|
||||||
|
|
||||||
( x1 + y1 + z1 => z0z1 )
|
( x1 + y1 + z1 => z0z1 )
|
||||||
#00 ;x1 LDA ;z0 LDA2 ADD2 ;z0 STA2
|
#00 ;m32/x1 LDA ;m32/z0 LDA2 ADD2 ;m32/z0 STA2
|
||||||
#00 ;y1 LDA ;z0 LDA2 ADD2 ;z0 STA2
|
#00 ;m32/y1 LDA ;m32/z0 LDA2 ADD2 ;m32/z0 STA2
|
||||||
|
|
||||||
( x0 + y0 + z0 => z0 )
|
( x0 + y0 + z0 => z0 )
|
||||||
;x0 LDA ;z0 LDA ADD ;z0 STA
|
;m32/x0 LDA ;m32/z0 LDA ADD ;m32/z0 STA
|
||||||
;y0 LDA ;z0 LDA ADD ;z0 STA
|
;m32/y0 LDA ;m32/z0 LDA ADD ;m32/z0 STA
|
||||||
|
|
||||||
( load zhi,zlo )
|
( load zhi,zlo )
|
||||||
;z0 LDA2 ;z2 LDA2
|
;m32/z0 LDA2 ;m32/z2 LDA2
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( -x )
|
( -x )
|
||||||
@negate32 ( x** -> -x** )
|
@negate32 ( x** -> -x** )
|
||||||
|
@ -298,36 +295,36 @@
|
||||||
,&done JCN ( xlo non-zero => don't inc hi )
|
,&done JCN ( xlo non-zero => don't inc hi )
|
||||||
SWP2 INC2 SWP2 ( -xhi -xlo )
|
SWP2 INC2 SWP2 ( -xhi -xlo )
|
||||||
&done
|
&done
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( x - y )
|
( x - y )
|
||||||
@sub32 ( x** y** -> z** )
|
@sub32 ( x** y** -> z** )
|
||||||
;negate32 JSR2 ;add32 JSR2 RTN
|
;negate32 JSR2 ;add32 JSR2 JMP2r
|
||||||
|
|
||||||
( 16-bit multiplication )
|
( 16-bit multiplication )
|
||||||
@mul16 ( x* y* -> z** )
|
@mul16 ( x* y* -> z** )
|
||||||
;y1 STA ;y0 STA ( save ylo, yhi )
|
;m32/y1 STA ;m32/y0 STA ( save ylo, yhi )
|
||||||
;x1 STA ;x0 STA ( save xlo, xhi )
|
;m32/x1 STA ;m32/x0 STA ( save xlo, xhi )
|
||||||
#0000 #00 ;z1 STA2 ;z3 STA ( reset z1,z2,z3 )
|
#0000 #00 ;m32/z1 STA2 ;m32/z3 STA ( reset z1,z2,z3 )
|
||||||
#0000 #00 ;w0 STA2 ;w2 STA ( reset w0,w1,w2 )
|
#0000 #00 ;m32/w0 STA2 ;m32/w2 STA ( reset w0,w1,w2 )
|
||||||
|
|
||||||
( x1 * y1 => z1z2 )
|
( x1 * y1 => z1z2 )
|
||||||
#00 ;x1 LDA #00 ;y1 LDA MUL2 ;z2 STA2
|
#00 ;m32/x1 LDA #00 ;m32/y1 LDA MUL2 ;m32/z2 STA2
|
||||||
|
|
||||||
( x0 * y1 => z0z1 )
|
( x0 * y1 => z0z1 )
|
||||||
#00 ;x0 LDA #00 ;y1 LDA MUL2 ;z1 LDA2 ADD2 ;z1 STA2
|
#00 ;m32/x0 LDA #00 ;m32/y1 LDA MUL2 ;m32/z1 LDA2 ADD2 ;m32/z1 STA2
|
||||||
|
|
||||||
( x1 * y0 => w1w2 )
|
( x1 * y0 => w1w2 )
|
||||||
#00 ;x1 LDA #00 ;y0 LDA MUL2 ;w1 STA2
|
#00 ;m32/x1 LDA #00 ;m32/y0 LDA MUL2 ;m32/w1 STA2
|
||||||
|
|
||||||
( x0 * y0 => w0w1 )
|
( x0 * y0 => w0w1 )
|
||||||
#00 ;x0 LDA #00 ;y0 LDA MUL2 ;w0 LDA2 ADD2 ;w0 STA2
|
#00 ;m32/x0 LDA #00 ;m32/y0 LDA MUL2 ;m32/w0 LDA2 ADD2 ;m32/w0 STA2
|
||||||
|
|
||||||
( add z and a<<8 )
|
( add z and a<<8 )
|
||||||
#00 ;z1 LDA2 ;z3 LDA
|
#00 ;m32/z1 LDA2 ;m32/z3 LDA
|
||||||
;w0 LDA2 ;w2 LDA #00
|
;m32/w0 LDA2 ;m32/w2 LDA #00
|
||||||
;add32 JSR2
|
;add32 JSR2
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( x * y )
|
( x * y )
|
||||||
@mul32 ( x** y** -> z** )
|
@mul32 ( x** y** -> z** )
|
||||||
|
@ -340,7 +337,7 @@
|
||||||
( [x0*y0]<<32 will completely overflow )
|
( [x0*y0]<<32 will completely overflow )
|
||||||
ADD2 ,&z0 LDR2 ADD2 ( sum += x0*y1<<16 + x1*y0<<16 )
|
ADD2 ,&z0 LDR2 ADD2 ( sum += x0*y1<<16 + x1*y0<<16 )
|
||||||
,&z1 LDR2
|
,&z1 LDR2
|
||||||
RTN
|
JMP2r
|
||||||
[ &x0 $2 &x1 $2
|
[ &x0 $2 &x1 $2
|
||||||
&y0 $2 &y1 $2
|
&y0 $2 &y1 $2
|
||||||
&z0 $2 &z1 $2 ]
|
&z0 $2 &z1 $2 ]
|
||||||
|
@ -348,18 +345,18 @@
|
||||||
@div32 ( x** y** -> q** )
|
@div32 ( x** y** -> q** )
|
||||||
;_divmod32 JSR2
|
;_divmod32 JSR2
|
||||||
;_divmod32/quo0 LDA2 ;_divmod32/quo1 LDA2
|
;_divmod32/quo0 LDA2 ;_divmod32/quo1 LDA2
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
@mod32 ( x** y** -> r** )
|
@mod32 ( x** y** -> r** )
|
||||||
;_divmod32 JSR2
|
;_divmod32 JSR2
|
||||||
;_divmod32/rem0 LDA2 ;_divmod32/rem1 LDA2
|
;_divmod32/rem0 LDA2 ;_divmod32/rem1 LDA2
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
@divmod32 ( x** y** -> q** r** )
|
@divmod32 ( x** y** -> q** r** )
|
||||||
;_divmod32 JSR2
|
;_divmod32 JSR2
|
||||||
;_divmod32/quo0 LDA2 ;_divmod32/quo1 LDA2
|
;_divmod32/quo0 LDA2 ;_divmod32/quo1 LDA2
|
||||||
;_divmod32/rem0 LDA2 ;_divmod32/rem1 LDA2
|
;_divmod32/rem0 LDA2 ;_divmod32/rem1 LDA2
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( calculate and store x / y and x % y )
|
( calculate and store x / y and x % y )
|
||||||
@_divmod32 ( x** y** -> )
|
@_divmod32 ( x** y** -> )
|
||||||
|
@ -372,7 +369,7 @@
|
||||||
,&div0 LDR2 ,&div1 LDR2
|
,&div0 LDR2 ,&div1 LDR2
|
||||||
;lt32 JSR2 ,&is-zero JCN ,¬-zero JMP
|
;lt32 JSR2 ,&is-zero JCN ,¬-zero JMP
|
||||||
&is-zero
|
&is-zero
|
||||||
#0000 ,&quo0 STR2 #0000 ,&quo1 STR2 RTN
|
#0000 ,&quo0 STR2 #0000 ,&quo1 STR2 JMP2r
|
||||||
|
|
||||||
( x >= y so the answer is >= 1 )
|
( x >= y so the answer is >= 1 )
|
||||||
¬-zero
|
¬-zero
|
||||||
|
@ -412,7 +409,7 @@
|
||||||
,&div0 LDR2 ,&div1 LDR2 #01 ;rshift32 JSR2 ,&div1 STR2 ,&div0 STR2 ( div >>= 1 )
|
,&div0 LDR2 ,&div1 LDR2 #01 ;rshift32 JSR2 ,&div1 STR2 ,&div0 STR2 ( div >>= 1 )
|
||||||
,&cur0 LDR2 ,&cur1 LDR2 #01 ;rshift32 JSR2 ,&cur1 STR2 ,&cur0 STR2 ( cur >>= 1 )
|
,&cur0 LDR2 ,&cur1 LDR2 #01 ;rshift32 JSR2 ,&cur1 STR2 ,&cur0 STR2 ( cur >>= 1 )
|
||||||
,&cur0 LDR2 ,&cur1 LDR2 ;non-zero32 JSR2 ,&loop JCN ( if cur>0, loop. else we're done )
|
,&cur0 LDR2 ,&cur1 LDR2 ;non-zero32 JSR2 ,&loop JCN ( if cur>0, loop. else we're done )
|
||||||
RTN
|
JMP2r
|
||||||
|
|
||||||
( greatest common divisor - euclidean algorithm )
|
( greatest common divisor - euclidean algorithm )
|
||||||
@gcd32 ( x** y** -> z** )
|
@gcd32 ( x** y** -> z** )
|
||||||
|
@ -432,4 +429,4 @@
|
||||||
,&loop JMP
|
,&loop JMP
|
||||||
&done
|
&done
|
||||||
POP4 ( x )
|
POP4 ( x )
|
||||||
RTN
|
JMP2r
|
||||||
|
|
Loading…
Reference in New Issue