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

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [software/] [sample code/] [sieve.lis] - Blame information for rev 46

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 robfinch
     1  /*#include */
2
     2
3
     3  #define LIMIT 1500000 /*size of integers array*/
4
     4  #define PRIMES 100000 /*size of primes array*/
5
     5
6
     6  nocall my_org() {
7
     7          asm {
8
     8                  org     0x100800200
9
     9                  db      "BOOT"
10
    10                  jmp     crt_start
11
    11                  .align 8
12
    12  sp_save:
13
    13                  dw      0
14
    14          }
15
    15  }
16
    16
17
 
18
 
19
*** local symbol table ***
20
 
21
 
22
 
23
 
24
    17  int main(){
25
    18      int i,j,numbers[LIMIT];
26
    19      int primes[PRIMES];
27
    20          int limit;
28
    21          int start_tick,end_tick;
29
    22
30
    23          asm {
31
    24                  sei
32
    25                  lw              r1,#0xAB
33
    26                  outb    r1,0xdc0600
34
    27          }
35
    28          start_tick = get_tick();
36
    29          asm {
37
    30                  lw              r1,#0xAC
38
    31                  outb    r1,0xdc0600
39
    32          }
40
    33          printf("Start tick %d\r\n", start_tick);
41
    34          asm {
42
    35                  lw              r1,#0xAD
43
    36                  outb    r1,0xdc0600
44
    37                  cli
45
    38          }
46
    39
47
    40          limit=LIMIT;
48
    41
49
    42      /*fill the array with natural numbers*/
50
    43          for (i=0;i
51
    44                  numbers[i]=i+2;
52
    45          }
53
    46
54
    47      /*sieve the non-primes*/
55
    48      for (i=0;i
56
    49          if (numbers[i]!=-1){
57
    50              for (j=2*numbers[i]-2;j
58
    51                  numbers[j]=-1;
59
    52          }
60
    53      }
61
    54
62
    55      /*transfer the primes to their own array*/
63
    56      j = 0;
64
    57      for (i=0;i
65
    58          if (numbers[i]!=-1)
66
    59              primes[j++] = numbers[i];
67
    60
68
    61          end_tick = get_tick();
69
    62          printf("Clock ticks %d\r\n", end_tick-start_tick);
70
    63
71
    64      /*print*/
72
    65      for (i=0;i
73
    66          printf("%d\n",primes[i]);
74
    67
75
    68  return 0;
76
    69  }
77
    70
78
 
79
 
80
*** local symbol table ***
81
 
82
i          =fffffff8    -    Auto        Long
83
j          =fffffff0    -    Auto        Long
84
numbers    =ff48e4f0    -    Auto        Array of Long
85
primes     =ff3caff0    -    Auto        Array of Long
86
limit      =ff3cafe8    -    Auto        Long
87
start_tick =ff3cafe0    -    Auto        Long
88
end_tick   =ff3cafd8    -    Auto        Long
89
 
90
 
91
 
92
    71  int printf(char *p)
93
    72  {
94
    73          int *q;
95
    74          asm {
96
    75                  lw              r1,#0xAE
97
    76                  outb    r1,0xdc0600
98
    77          }
99
    78          q = &p;
100
    79
101
    80          for (; *p; p++) {
102
    81                  if (*p=='%') {
103
    82                          p++;
104
    83                          switch(*p) {
105
    84                          case '%':
106
    85                                  putch('%');
107
    86                                  break;
108
    87                          case 'c':
109
    88                                  q++;
110
    89                                  putch(*q);
111
    90                                  break;
112
    91                          case 'd':
113
    92                                  q++;
114
    93                                  putnum(*q);
115
    94                                  break;
116
    95                          case 's':
117
    96                                  q++;
118
    97                                  putstr(*q);
119
    98                                  break;
120
    99                          }
121
   100                  }
122
   101                  else
123
   102                          putch(*p);
124
   103          }
125
   104  }
126
   105
127
 
128
 
129
*** local symbol table ***
130
 
131
p          =000018    -    Auto        Pointer to Char
132
q          =fffffff8    -    Auto        Pointer to Long
133
 
134
 
135
 
136
   106  void putch(char ch)
137
   107  {
138
   108          asm {
139
   109                  lw              r1,#0xAF
140
   110                  outb    r1,0xdc0600
141
   111          }
142
   112          asm {
143
   113                  lw              r1,#0x0a
144
   114                  lw              r2,24[bp]
145
   115                  lw              r3,#1
146
   116                  syscall #410
147
   117          }
148
   118          asm {
149
   119                  lw              r1,#0xB0
150
   120                  outb    r1,0xdc0600
151
   121          }
152
   122  }
153
   123
154
 
155
 
156
*** local symbol table ***
157
 
158
ch         =000018    -    Auto        Char
159
 
160
 
161
 
162
   124  void putnum(int num)
163
   125  {
164
   126          asm {
165
   127                  lw              r1,#0xB1
166
   128                  outb    r1,0xdc0600
167
   129          }
168
   130          asm {
169
   131                  lw              r1,#0x15
170
   132                  lw              r2,24[bp]
171
   133                  lw              r3,#5
172
   134                  syscall #410
173
   135          }
174
   136          asm {
175
   137                  lw              r1,#0xB2
176
   138                  outb    r1,0xdc0600
177
   139          }
178
   140  }
179
   141
180
 
181
 
182
*** local symbol table ***
183
 
184
num        =000018    -    Auto        Long
185
 
186
 
187
 
188
   142  void putstr(char *p)
189
   143  {
190
   144          asm {
191
   145                  lw              r1,#0x14
192
   146                  lw              r2,24[bp]
193
   147                  syscall #410
194
   148          }
195
   149  }
196
   150
197
 
198
 
199
*** local symbol table ***
200
 
201
p          =000018    -    Auto        Pointer to Char
202
 
203
 
204
 
205
   151  int get_tick()
206
   152  {
207
   153          asm {
208
   154                  lw              r1,#0
209
   155                  syscall #416
210
   156          }
211
   157  }
212
   158
213
 
214
 
215
*** local symbol table ***
216
 
217
 
218
 
219
 
220
   159  void crt_start()
221
   160  {
222
   161          asm {
223
   162                  lw              r1,#0xAA
224
   163                  outb    r1,0xdc0600
225
   164                  sw              sp,sp_save
226
   165                  lw              sp,#0x1_07FFFFF8
227
   166                  lea             xlr,prog_abort
228
   167                  call    main
229
   168                  lw              sp,sp_save
230
   169                  bra             retcode
231
   170  prog_abort:
232
   171          }
233
   172          putstr("Program aborted abnormally.");
234
   173          asm {
235
   174                  lw      sp,sp_save
236
   175  retcode:
237
   176          }
238
   177  }
239
 
240
 
241
*** local symbol table ***
242
 
243
 
244
 
245
 
246
 
247
 *** global scope typedef symbol table ***
248
 
249
putch      =000000    -    Global      Function returning
250
get_tick   =000000    -    Global      Function returning Long
251
my_org     =000000    -    Global      Function returning
252
printf     =000000    -    Global      Function returning Long
253
main       =000000    -    Global      Function returning Long
254
putnum     =000000    -    Global      Function returning
255
putstr     =000000    -    Global      Function returning
256
crt_start  =000000    -    Global      Function returning
257
 
258
 *** structures and unions ***
259
 

powered by: WebSVN 2.1.0

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