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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [fp/] [implementation/] [mmix/] [copy.mms] - Blame information for rev 274

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

Line No. Rev Author Line
1 15 hellwig
* SAMPLE PROGRAM: COPY A GIVEN FILE TO STANDARD OUTPUT
2
 
3
t        IS   $255
4
argc     IS   $0
5
argv     IS   $1
6
s        IS   $2
7
Buf_Size IS   5                 ridiculously small for testing
8
         LOC  Data_Segment
9
Buffer   LOC  @+Buf_Size
10
         GREG @
11
Arg0     OCTA 0,TextRead
12
Arg1     OCTA Buffer,Buf_Size
13
 
14
         LOC  #200              main(argc,argv) {
15
Main     CMP  t,argc,2          if (argc==2) goto openit
16
         PBZ  t,OpenIt
17
         GETA t,1F              fputs("Usage: ",stderr)
18
         TRAP 0,Fputs,StdErr
19
         LDOU t,argv,0          fputs(argv[0],stderr)
20
         TRAP 0,Fputs,StdErr
21
         GETA t,2F              fputs(" filename\n",stderr)
22
Quit     TRAP 0,Fputs,StdErr
23
         NEG  t,0,1             quit: exit(-1)
24
         TRAP 0,Halt,0
25
1H       BYTE "Usage: ",0
26
         LOC  (@+3)&-4          align to tetrabyte
27
2H       BYTE " filename",#a,0
28
 
29
OpenIt   LDOU s,argv,8          openit: s=argv[1]
30
         STOU s,Arg0
31
         LDA  t,Arg0            fopen(argv[1],"r",file[3])
32
         TRAP 0,Fopen,3
33
         PBNN t,CopyIt          if (no error) goto copyit
34
         GETA t,1F              fputs("Can't open file ",stderr)
35
         TRAP 0,Fputs,StdErr
36
         SET  t,s               fputs(argv[1],stderr)
37
         TRAP 0,Fputs,StdErr
38
         GETA t,2F              fputs("!\n",stderr)
39
         JMP  Quit              goto quit
40
1H       BYTE "Can't open file ",0
41
         LOC  (@+3)&-4          align to tetrabyte
42
2H       BYTE "!",#a,0
43
 
44
CopyIt   LDA  t,Arg1            copyit:
45
         TRAP 0,Fread,3         items=fread(buffer,1,buf_size,file[3])
46
         BN   t,EndIt           if (items < buf_size) goto endit
47
         LDA  t,Arg1            items=fwrite(buffer,1,buf_size,stdout)
48
         TRAP 0,Fwrite,StdOut
49
         PBNN t,CopyIt          if (items >= buf_size) goto copyit
50
Trouble  GETA t,1F              trouble: fputs("Trouble w...!",stderr)
51
         JMP  Quit              goto quit
52
1H       BYTE "Trouble writing StdOut!",#a,0
53
 
54
EndIt    INCL t,Buf_Size
55
         BN   t,ReadErr         if (ferror(file[3])) goto readerr
56
         STO  t,Arg1+8
57
         LDA  t,Arg1            n=fwrite(buffer,1,items,stdout)
58
         TRAP 0,Fwrite,StdOut
59
         BN   t,Trouble         if (n < items) goto trouble
60
         TRAP 0,Halt,0          exit(0)
61
ReadErr  GETA t,1F              readerr: fputs("Trouble r...!",stderr)
62
         JMP  Quit              goto quit }
63
1H       BYTE "Trouble reading!",#a,0

powered by: WebSVN 2.1.0

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