OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [fp/] [implementation/] [mmix/] [permu-heap.mms] - Blame information for rev 190

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 hellwig
* Permutation generator a la Heap
2
N  IS   5               $n$ (3, 4, 5, or 6)
3
t  IS   $255
4
j  IS   $0              $8j$
5
k  IS   $1              $8k$
6
ak IS   $2
7
aj IS   $3
8
 
9
   LOC  Data_Segment
10
a  GREG @               Base address for $a_0\ldots a_{n-1}$
11
A0 IS   @
12
A1 IS   @+8
13
A2 IS   @+16
14
*  LOC  @+8*N           Space for $a_0\ldots a_{n-1}$
15
   BYTE "11111111","22222222","33333333"
16
   BYTE "44444444","55555555","66666666"
17
   BYTE #a,0
18
   LOC  (@+7)&-8        (align to octabyte)
19
c  GREG @-8*3           Location of $c_0$
20
   LOC  @-8*3+8*N       $8c_3\ldots 8c_{n-1}$, initially zero
21
   OCTA -1              $c_n=-1$, a convenient sentinel
22
u  GREG 0               Contents of $a_0$, except in inner loop
23
v  GREG 0               Contents of $a_1$, except in inner loop
24
w  GREG 0               Contents of $a_2$, except in inner loop
25
 
26
   LOC  #100
27
1H STCO 0,c,k           $c_k\gets 0$.
28
   INCL k,8             $k\gets k+1$.
29
0H LDO  j,c,k           $j\gets c_k$.
30
   CMP  t,j,k
31
   BZ   t,1B            Loop if $c_k=k$.
32
   BN   j,Done          Terminate if $c_k<0$ ($k=n$).
33
   LDO  ak,a,k          Fetch $a_k$.
34
   ADD  t,j,8
35
   STO  t,c,k           $c_k\gets j+1$.
36
   AND  t,k,#8
37
   CSZ  j,t,0           Set $j\gets 0$ if $k$ is even.
38
   LDO  aj,a,j          Fetch $a_j$.
39
   STO  ak,a,j          Replace it by $a_k$.
40
   CSZ  u,j,ak          Set $u\gets a_k$ if $j=0$.
41
   SUB  j,j,8           $j\gets j-1$.
42
   CSZ  v,j,ak          Set $v\gets a_k$ if $j=0$.
43
   SUB  j,j,8           $j\gets j-1$.
44
   CSZ  w,j,ak          Set $w\gets a_k$ if $j=0$.
45
   STO  aj,a,k          Replace $a_k$ by what was $a_j$.
46
In PUSHJ 0,Visit
47
   STO   v,A0           $a_0\gets v$.
48
   STO   u,A1           $a_1\gets u$.
49
   PUSHJ 0,Visit
50
   STO   w,A0           $a_0\gets w$.
51
   STO   v,A2           $a_2\gets v$.
52
   PUSHJ 0,Visit
53
   STO   u,A0           $a_0\gets u$.
54
   STO   w,A1           $a_1\gets w$.
55
   PUSHJ 0,Visit
56
   STO   v,A0           $a_0\gets v$.
57
   STO   u,A2           $a_2\gets u$.
58
   PUSHJ 0,Visit
59
   STO   w,A0           $a_0\gets w$.
60
   STO   v,A1           $a_1\gets v$.
61
   PUSHJ 0,Visit
62
   SET   t,u            Swap $u\leftrightarrow w$.
63
   SET   u,w
64
   SET   w,t
65
   SET   k,8*3          $k\gets3$.
66
   JMP   0B
67
 
68
Visit LDA  t,A0
69
      TRAP 0,Fputs,StdOut
70
      POP
71
Main  LDO  u,A0
72
      LDO  v,A1
73
      LDO  w,A2
74
      JMP  In
75
Done  TRAP 0,Halt,0

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.