0aa257fd7614093c8b401727408058e501deaed1
[YACASL2.git] / doc / yacasl2.texi
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @ifnottex
4 @documentlanguage ja_JP
5 @end ifnottex
6 @setfilename yacasl2.info
7 @settitle YACASL2 - Linux上のCASL II処理系
8 @firstparagraphindent insert
9 @paragraphindent 1
10 @c %**end of header
11
12 @copying
13 Copyright @copyright{} 2010 j8takagi
14 @end copying
15
16 @exampleindent 2
17
18 @dircategory Basics
19 @direntry
20 * YACASL2: (yacasl2).
21 @end direntry
22
23 @titlepage
24 @title YACASL2
25 @subtitle Linux上のCASL II処理系
26 @author j8takagi
27 @insertcopying
28 @end titlepage
29
30 @ifnottex
31 @node Top
32 @end ifnottex
33
34 @menu
35 * YACASL2の概要::
36 * YACASL2のインストール::
37 * YACASL2の使い方::
38 * YACASL2コマンドマニュアル::
39 @end menu
40
41 @contents
42
43 @node YACASL2の概要, YACASL2のインストール, Top, Top
44 @chapter YACASL2の概要
45
46 YACASL2は、Linux上で動作するオープンソースのCASL II処理系です。CASL IIは情報処理試験で用いられるアセンブラ言語で、次の資料により仕様が公開されています。
47
48 @iftex
49 @cartouche
50 @end iftex
51 @quotation
52 @uref{http://www.jitec.ipa.go.jp/1_00topic/topic_20081027_hani_yougo.pdf, 試験で使用する情報処理用語・プログラム言語など(2008年10月版)}[PDFファイル]
53 別紙 1 アセンブラ言語の仕様
54 @end quotation
55 @iftex
56 @end cartouche
57 @end iftex
58
59 YACASL2は、CASL IIアセンブラ言語で記述されたファイルをアセンブルし、仮想マシンCOMET II上で実行します。アセンブルと実行は、連続で行うことも別々に行うことも可能です。
60 YACASL2の動作はCASL IIの仕様に準拠しているため、情報処理試験の問題をはじめ各種参考書やサイトに記載されたCASL IIのプログラムをそのままアセンブルして実行できます。また、本パッケージ中にCASL IIのサンプルプログラムが多数収録されています。
61
62 YACASL2は、「ふつうの処理系」として動作します。ほかの多くのCASL IIエミュレータと違い、デバッガとして動作したり、コンピュータ内部の模式図を表示したりすることはありません。そのかわり、YACASL2は、次のような動作内容をすべてテキストで出力します。
63
64 @itemize @bullet
65
66 @item
67 ラベルとアドレスの対応
68
69 @item
70 アセンブル結果
71
72 @item
73 実行時のレジスタの内容
74
75 @item
76 実行時のメモリの内容
77 @end itemize
78
79 出力された動作内容は、GNU/Linuxのさまざまなツール、たとえば@command{cat}、@command{less}、@command{grep}、@command{wc}などを使って解析できます。
80
81 YACASL2の操作は、端末を開いてコマンドを入力・実行することで行います。
82
83 @unnumberedsec 要件
84 YACASL2は、Linux上で動作します。現在動作を確認しているのは、次のディストリビューションです。
85
86 @itemize @bullet
87
88 @item
89 Ubuntu Linux 9.04 / 8.04
90
91 @item
92 Vine Linux 4.2
93 @end itemize
94
95 インストール時に、@command{tar}、@command{gcc}、@command{make}が必要です。
96
97 @node YACASL2のインストール, YACASL2の使い方, YACASL2の概要, Top
98 @chapter YACASL2のインストール
99 YACASL2をインストールするには、Linux上で次の作業をします。
100
101 @enumerate
102
103 @item
104 @file{yacasl2.tar.gz}のダウンロード
105
106 @item
107 @file{yacasl2.tar.gz}の検証
108
109 @item
110 @file{yacasl2.tar.gz}の展開
111
112 @item
113 @command{casl2}、@command{comet2}、@command{dumpword}のビルド
114
115 @item
116 @command{casl2}の実行テスト
117
118 @item
119 詳細なテスト
120
121 @item
122 環境変数@var{PATH}の設定
123 @end enumerate
124
125 @section @file{yacasl2.tar.gz}のダウンロード
126 (詳細未定)
127
128 @iftex
129 @cartouche
130 @end iftex
131 @example
132 $ @command{cd}
133 $ @command{wget somewhere/yacasl2.tar.gz}
134 $ @command{wget somewhere/yacasl2.tar.gz.md5sum}
135 @end example
136 @iftex
137 @end cartouche
138 @end iftex
139
140 @section @file{yacasl2.tar.gz}の検証
141
142 (PGPを使った検証も導入予定)
143
144 ダウンロードが完了したら、@command{md5sum}と@command{diff}で正しくファイルがダウンロードができているかを検証します。
145
146 @iftex
147 @cartouche
148 @end iftex
149 @example
150 $ @command{md5sum yacasl2.tar.gz | diff -s yacasl2.tar.gz.md5sum -}
151 Files yacasl2.tar.gz.md5sum and - are identical
152 @end example
153 @iftex
154 @end cartouche
155 @end iftex
156
157 @section @file{yacasl2.tar.gz}の展開
158
159 @file{yacasl2.tar.gz}をダウンロードしたら、次のコマンドで展開します。
160
161 @iftex
162 @cartouche
163 @end iftex
164 @example
165 $ @command{tar xvzf yacasl2.tar.gz}
166 @end example
167 @iftex
168 @end cartouche
169 @end iftex
170
171 @section @command{casl2}、@command{comet2}、@command{dumpword}のビルド
172
173 展開したら、次のコマンドで@command{casl2}、@command{comet2}、@command{dumpword}をビルドします。
174
175 @iftex
176 @cartouche
177 @end iftex
178 @example
179 $ @command{cd yacasl2}
180 $ @command{make}
181 make -C src
182 make[1]: Entering directory ‘/home/kazubito/yacasl2/src’
183 gcc -c -g -Wall -I ../include casl2.c
184 gcc -c -g -Wall -I ../include word.c
185 gcc -c -g -Wall -I ../include hash.c
186 gcc -c -g -Wall -I ../include cerr.c
187 gcc -c -g -Wall -I ../include struct.c
188 gcc -c -g -Wall -I ../include cmd.c
189 gcc -c -g -Wall -I ../include assemble.c
190 gcc -c -g -Wall -I ../include token.c
191 gcc -c -g -Wall -I ../include label.c
192 gcc -c -g -Wall -I ../include macro.c
193 gcc -c -g -Wall -I ../include exec.c
194 gcc -c -g -Wall -I ../include dump.c
195 gcc -g -Wall -I ../include -o ../casl2 casl2.o word.o hash.o cerr.o st
196 ruct.o cmd.o assemble.o token.o label.o macro.o exec.o dump.o
197 gcc -c -g -Wall -I ../include comet2.c
198 gcc -g -Wall -I ../include -o ../comet2 comet2.o word.o hash.o cerr.o
199 struct.o cmd.o exec.o dump.o
200 gcc -c -g -Wall -I ../include dumpword.c
201 gcc -g -Wall -I ../include -o ../dumpword dumpword.o word.o cerr.o
202 make[1]: Leaving directory ‘/home/kazubito/yacasl2/src’
203 @end example
204 @iftex
205 @end cartouche
206 @end iftex
207
208 @section @command{casl2}の実行テスト
209
210 ビルドしたら、次のコマンドが正常に実行できるかを確認します。
211 正常に実行された場合は、「Hello, World!」と表示されます。
212
213 @iftex
214 @cartouche
215 @end iftex
216 @example
217 $ @command{./casl2 as/hello.casl}
218 Hello, World!
219 @end example
220 @iftex
221 @end cartouche
222 @end iftex
223
224 @section 詳細なテスト
225
226 次のコマンドを実行すると、正常にビルドできているかどうかを詳細にテストできます。
227
228 @iftex
229 @cartouche
230 @end iftex
231 @example
232 $ @command{make check}
233 194 / 194 tests passed. Details in /home/kazubito/yacasl2/test/integra
234 tion/casl2/Test.log
235 All tests are succeded.
236 149 / 149 tests passed. Details in /home/kazubito/yacasl2/test/integra
237 tion/comet2/Test.log
238 All tests are succeded.
239 4 / 4 tests passed. Details in /home/kazubito/yacasl2/test/integration
240 /dumpword/Test.log
241 All tests are succeded.
242 @end example
243 @iftex
244 @end cartouche
245 @end iftex
246
247 @section 環境変数@var{PATH}の設定
248
249 環境変数@var{PATH}にYACASL2のディレクトリを追加すると、どのディレクトリでも@command{casl2}、@command{comet2}、@command{dumpword}を実行できます。
250
251 環境変数の設定方法は使っているシェルによって異なります。シェルは、次のコマンドで確認できます。
252
253 @iftex
254 @cartouche
255 @end iftex
256 @example
257 $ @command{echo $SHELL}
258 /bin/bash
259 @end example
260 @iftex
261 @end cartouche
262 @end iftex
263
264 現在もっとも多く使われているシェルは、BASHでしょう。BASHでは、次のコマンドを実行すると環境変数@var{PATH}にYACASL2のディレクトリが追加されます。
265
266 @iftex
267 @cartouche
268 @end iftex
269 @example
270 $ @command{PATH=$PATH:~/yacasl2 && export PATH}
271 @end example
272 @iftex
273 @end cartouche
274 @end iftex
275
276 シェルの初期設定ファイルに上記のコマンドを追加すれば、今後ログインした後は自動的にどのディレクトリでも @command{casl2}、@command{comet2}、@command{dumpword}を実行できます。BASHではホームディレクトリにある@file{.bashrc}が初期設定ファイルのため、次のコマンドで追加されます。
277
278 @iftex
279 @cartouche
280 @end iftex
281 @example
282 $ @command{echo ’PATH=$PATH:~/yacasl2 && export PATH’ >>~/.bashrc}
283 @end example
284 @iftex
285 @end cartouche
286 @end iftex
287
288 @node YACASL2の使い方, YACASL2コマンドマニュアル, YACASL2のインストール, Top
289 @chapter YACASL2 の使い方
290 YACASL2 は、テキストファイルに記述されたCASLプログラムを処理します。以下の例で用いられるCASLプログラムのファイルは、テキストエディタなどで作成してください。また、インストールしたディレクトリの中にある@file{as}ディレクトリからコピーして作成することもできます。
291
292 @section 実行結果の出力だけを表示
293
294 インストール時にコマンド実行の確認に使った@file{hello.casl}は、次のような内容です。CASL IIのマクロ命令OUTは、文字列を出力します。
295
296 @iftex
297 @cartouche
298 @end iftex
299 @example
300 $ @command{cat hello.casl}
301 MAIN     START
302          OUT     OBUF,LEN
303          RET
304 OBUF     DC      ’Hello, World!’
305 LEN      DC      13
306          END
307 @end example
308 @iftex
309 @end cartouche
310 @end iftex
311
312 次のコマンドを実行すると、CASL II のアセンブルと仮想マシン COMET II 上での実行が連続で行われ、文字列が出力されます。
313
314 @iftex
315 @cartouche
316 @end iftex
317 @example
318 $ @command{casl2 hello.casl}
319 Hello, World!
320 @end example
321 @iftex
322 @end cartouche
323 @end iftex
324
325 @file{addl.casl}は、3と1の和を求めます。
326
327 @iftex
328 @cartouche
329 @end iftex
330 @example
331 $ @command{cat addl.casl}
332 ;;; ADDL r,adr
333 MAIN     START
334          LD      GR1,A
335          ADDL    GR1,B
336          RET
337 A        DC      3
338 B        DC      1
339          END
340 @end example
341 @iftex
342 @end cartouche
343 @end iftex
344
345 このプログラムには出力命令がないため、オプションなしで実行した場合には結果が出力されません。
346
347 @iftex
348 @cartouche
349 @end iftex
350 @example
351 $ @command{casl2 addl.casl}
352 $
353 @end example
354 @iftex
355 @end cartouche
356 @end iftex
357
358 実行内容を確認するには、後述のようにCPU 内にあるレジスタやメモリの内容を表示するか、結果を出力するための処理を追加する必要があります。
359
360 @file{sum_10.casl}は、1から10までの整数の和を求めます。
361
362 @iftex
363 @cartouche
364 @end iftex
365 @example
366 $ @command{cat sum_10.casl}
367 ;;; sum_10.casl
368 ;;; 出力 GR0: 1から10までの整数をすべて加算した値
369 MAIN    START
370         PUSH    0,GR1
371         LAD     GR0,0           ; GR0を初期化
372         LD      GR1,FST         ; GR1に初項を転送
373 LOOP    ADDL    GR0,GR1         ; ループ先頭
374         ADDL    GR1,STEP        ; GR1 <- GR1 + 公差
375         CPL     GR1,LST         ; GR1が末項より大きい場合は終了
376         JPL     FIN             ; ↓
377         JUMP    LOOP            ; ループ終端
378 FIN     POP     GR1
379         RET
380 FST     DC      1               ; 初項
381 LST     DC      10              ; 末項
382 STEP    DC      1               ; 公差
383         END
384 @end example
385 @iftex
386 @end cartouche
387 @end iftex
388
389 このプログラムも、オプションなしで実行した場合には結果が出力されません。
390 @iftex
391 @cartouche
392 @end iftex
393 @example
394 $ @command{casl2 sum_10.casl}
395 $
396 @end example
397 @iftex
398 @end cartouche
399 @end iftex
400
401 @section アセンブル結果の確認
402 casl2の処理途中で行われるアセンブルの結果を表示するには、オプション@option{-a}を指定します。また、ラベルとアドレスの対応表を表示するには、オプション@option{-l}を指定します。
403
404 次のコマンドでは@file{hello.casl}の、ラベルとアドレスの対応表と、アセンブル結果と、実行結果が表示されます。OUTはアセンブラ命令で複数の機械語命令で構成されているため、命令行1行に対して、複数行のコードが生成されます。
405
406 @iftex
407 @cartouche
408 @end iftex
409 @example
410 $ @command{casl2 -a -l hello.casl}
411
412 Assemble hello.casl (0)
413
414 Label::::
415 MAIN.LEN ---> #0020
416 MAIN ---> #0000
417 MAIN.OBUF ---> #0013
418
419 Assemble hello.casl (1)
420 hello.casl:    1:MAIN    START
421 hello.casl:    2:        OUT     OBUF,LEN
422     #0000   #7001
423     #0001   #0000
424     #0002   #7002
425     #0003   #0000
426     #0004   #1210
427     #0005   #0013
428     #0006   #1220
429     #0007   #0020
430     #0008   #F000
431     #0009   #0002
432     #000A   #1210
433     #000B   #0021
434     #0021   #000A
435     #000C   #1220
436     #000D   #0022
437     #0022   #0001
438     #000E   #F000
439     #000F   #0002
440     #0010   #7120
441     #0011   #7110
442 hello.casl:    3:        RET
443     #0012   #8100
444 hello.casl:    4:OBUF    DC      'Hello, World!'
445     #0013   #0048
446     #0014   #0065
447     #0015   #006C
448     #0016   #006C
449     #0017   #006F
450     #0018   #002C
451     #0019   #0020
452     #001A   #0057
453     #001B   #006F
454     #001C   #0072
455     #001D   #006C
456     #001E   #0064
457     #001F   #0021
458 hello.casl:    5:LEN     DC      13
459     #0020   #000D
460 hello.casl:    6:        END
461 Hello, World!
462 @end example
463 @iftex
464 @end cartouche
465 @end iftex
466
467 @file{addl.casl}の、ラベルとアドレスの対応表と、アセンブル結果は、次のようになります。
468
469 @iftex
470 @cartouche
471 @end iftex
472 @example
473 $ @command{casl2 -a -l addl.casl}
474
475 Assemble addl.casl (0)
476
477 Label::::
478 MAIN.A ---> #0005
479 MAIN.B ---> #0006
480 MAIN ---> #0000
481
482 Assemble addl.casl (1)
483 addl.casl:    1:;;; ADDL r,adr
484 addl.casl:    2:MAIN    START
485 addl.casl:    3:        LD      GR1,A
486     #0000   #1010
487     #0001   #0005
488 addl.casl:    4:        ADDL    GR1,B
489     #0002   #2210
490     #0003   #0006
491 addl.casl:    5:        RET
492     #0004   #8100
493 addl.casl:    6:A       DC      3
494     #0005   #0003
495 addl.casl:    7:B       DC      1
496     #0006   #0001
497 addl.casl:    8:        END
498 @end example
499 @iftex
500 @end cartouche
501 @end iftex
502
503 なお、オプション@option{-A}を指定すると、アセンブル結果が表示される時点で処理が終了します。仮想マシンCOMET II での実行は行われません。
504
505 @section 実行時のレジスタとメモリを表示
506 YACASL2では実行中のCPUのレジスタとメモリの内容をそれぞれ、@option{-t}と@option{-d}を指定することで表示できます。
507
508 また、@option{-M}で、仮想マシンCOMET II のメモリ容量を語(16 ビット)単位で指定できます。小さいプログラムを実行するときは、メモリ容量を小さくすれば結果が見やすくなります。
509
510 @file{addl.casl}に必要なメモリ容量は8語のため、次のようにCPUのレジスタとメモリの内容を表示できます。
511
512 @iftex
513 @cartouche
514 @end iftex
515 @example
516 $ @command{casl2 -t -d -M8 addl.casl | less}
517
518 Assemble addl.casl (0)
519
520 Assemble addl.casl (1)
521
522 Executing machine codes
523 #0000: Register::::
524 #0000: GR0:      0 = #0000 = 0000000000000000
525 #0000: GR1:      0 = #0000 = 0000000000000000
526 #0000: GR2:      0 = #0000 = 0000000000000000
527 #0000: GR3:      0 = #0000 = 0000000000000000
528 #0000: GR4:      0 = #0000 = 0000000000000000
529 #0000: GR5:      0 = #0000 = 0000000000000000
530 #0000: GR6:      0 = #0000 = 0000000000000000
531 #0000: GR7:      0 = #0000 = 0000000000000000
532 #0000: SP:       8 = #0008 = 0000000000001000
533 #0000: PR:       0 = #0000 = 0000000000000000
534 #0000: FR (OF SF ZF): 000
535 #0000: Memory::::
536 #0000: adr : 0000 0001 0002 0003 0004 0005 0006 0007
537 #0000: 0000: 1010 0005 2210 0006 8100 0003 0001 0000 
538 #0002: Register::::
539 #0002: GR0:      0 = #0000 = 0000000000000000
540 #0002: GR1:      3 = #0003 = 0000000000000011
541 #0002: GR2:      0 = #0000 = 0000000000000000
542 #0002: GR3:      0 = #0000 = 0000000000000000
543 #0002: GR4:      0 = #0000 = 0000000000000000
544 #0002: GR5:      0 = #0000 = 0000000000000000
545 #0002: GR6:      0 = #0000 = 0000000000000000
546 #0002: GR7:      0 = #0000 = 0000000000000000
547 #0002: SP:       8 = #0008 = 0000000000001000
548 #0002: PR:       2 = #0002 = 0000000000000010
549 #0002: FR (OF SF ZF): 000
550 #0002: Memory::::
551 #0002: adr : 0000 0001 0002 0003 0004 0005 0006 0007
552 #0002: 0000: 1010 0005 2210 0006 8100 0003 0001 0000 
553 #0004: Register::::
554 #0004: GR0:      0 = #0000 = 0000000000000000
555 #0004: GR1:      4 = #0004 = 0000000000000100
556 #0004: GR2:      0 = #0000 = 0000000000000000
557 #0004: GR3:      0 = #0000 = 0000000000000000
558 #0004: GR4:      0 = #0000 = 0000000000000000
559 #0004: GR5:      0 = #0000 = 0000000000000000
560 #0004: GR6:      0 = #0000 = 0000000000000000
561 #0004: GR7:      0 = #0000 = 0000000000000000
562 #0004: SP:       8 = #0008 = 0000000000001000
563 #0004: PR:       4 = #0004 = 0000000000000100
564 #0004: FR (OF SF ZF): 000
565 #0004: Memory::::
566 #0004: adr : 0000 0001 0002 0003 0004 0005 0006 0007
567 #0004: 0000: 1010 0005 2210 0006 8100 0003 0001 0000 
568 @end example
569 @iftex
570 @end cartouche
571 @end iftex
572
573 @subsection 特定のレジスタを表示
574
575 @file{addl.casl}のレジスタやメモリの中で、実行中に値が変化しているのはGR1だけです。こうした場合は、@command{grep}を使って表示される内容を絞り込むことで動作を検証しやすくなります。
576
577 @iftex
578 @cartouche
579 @end iftex
580 @example
581 $ @command{casl2 -t addl.casl | grep 'GR1:'}
582 #0000: GR1:      0 = #0000 = 0000000000000000
583 #0002: GR1:      3 = #0003 = 0000000000000011
584 #0004: GR1:      4 = #0004 = 0000000000000100
585 @end example
586 @iftex
587 @end cartouche
588 @end iftex
589
590 この内容を、先に出力したアセンブル結果と引き比べてください。
591 次の表のように、PRとGR1、命令行が対応していることがわかります。
592
593 @multitable @columnfractions .3 .3 .4
594 @item PR @tab GR1 @tab 命令行
595 @item #0000
596 @tab #0000
597 @item #0002
598 @tab #0003
599 @tab @code{LD GR1,A}
600 @item #0004
601 @tab #0004
602 @tab @code{ADDL GR1,B}
603 @end multitable
604
605 @subsection プログラム終了時の値を表示
606
607 @command{grep}と@command{tail}を組み合わせれば、プログラム終了時の値を表示できます。
608
609 @iftex
610 @cartouche
611 @end iftex
612 @example
613 $ @command{casl2 -t addl.casl | grep 'GR1:' | tail -1}
614 #0004: GR1:      4 = #0004 = 0000000000000100
615 @end example
616 @iftex
617 @end cartouche
618 @end iftex
619
620 @iftex
621 @cartouche
622 @end iftex
623 @example
624 $ @command{casl2 -t sum_10.casl | grep 'GR0:' | tail -1}
625 #0010: GR0:     55 = #0037 = 0000000000110111 = '7'
626 @end example
627 @iftex
628 @end cartouche
629 @end iftex
630
631 @subsection プログラムのステップ数を表示
632
633 @command{grep}と@command{wc}を組み合わせれば、プログラムのステップ数を表示できます。
634
635 @iftex
636 @cartouche
637 @end iftex
638 @example
639 $ @command{casl2 -t hello.casl | grep 'GR1:' | wc -l}
640 11
641 @end example
642 @iftex
643 @end cartouche
644 @end iftex
645
646 @iftex
647 @cartouche
648 @end iftex
649 @example
650 $ @command{casl2 -t addl.casl | grep 'GR1:' | wc -l}
651 3
652 @end example
653 @iftex
654 @end cartouche
655 @end iftex
656
657 @file{sum_10.casl}はプログラム内にループがあるため、ステップ数が大きくなります。
658
659 @iftex
660 @cartouche
661 @end iftex
662 @example
663 $ @command{casl2 -t sum_10.casl | grep 'GR0:' | wc -l}
664 54
665 @end example
666 @iftex
667 @end cartouche
668 @end iftex
669
670 @section アセンブルと実行を別に行う
671
672 @command{casl2}に@option{-O}@file{ファイル名}を指定すると、オブジェクトファイルを作成できます。
673
674 @iftex
675 @cartouche
676 @end iftex
677 @example
678 $ @command{casl2 -Ohello.o hello.casl}
679 @end example
680 @iftex
681 @end cartouche
682 @end iftex
683
684 作成されたオブジェクトファイルの内容は、@command{od}を使って確認できます。テキストファイルではないため、@command{cat}などでは確認できません。
685
686 @iftex
687 @cartouche
688 @end iftex
689 @example
690 $ @command{od -t x2 hello.o}
691 0000000 7001 0000 7002 0000 1210 0013 1220 0020
692 0000020 f000 0002 1210 0021 1220 0022 f000 0002
693 0000040 7120 7110 8100 0048 0065 006c 006c 006f
694 0000060 002c 0020 0057 006f 0072 006c 0064 0021
695 0000100 000d 000a 0001
696 0000106
697 @end example
698 @iftex
699 @end cartouche
700 @end iftex
701
702 オブジェクトファイルの実行には、@command{comet2}を使います。
703
704 @iftex
705 @cartouche
706 @end iftex
707 @example
708 $ @command{comet2 hello.o}
709 Hello, World!
710 @end example
711 @iftex
712 @end cartouche
713 @end iftex
714
715 @section 1語の解析
716
717 CASL IIでは、1語(16ビット)を単位としてデータが処理されます。
718 @command{dumpword}は、指定した1語を10進数、16進数、2進数で表示します。
719
720 @iftex
721 @cartouche
722 @end iftex
723 @example
724 $ @command{dumpword 72}
725     72:     72 = #0048 = 0000000001001000 = 'H'
726 @end example
727 @iftex
728 @end cartouche
729 @end iftex
730
731 マイナスの数は、次のように指定します。
732
733 @iftex
734 @cartouche
735 @end iftex
736 @example
737 $ @command{dumpword} @option{--} @command{-72}
738    -72:    -72 = #FFB8 = 1111111110111000
739 @end example
740 @iftex
741 @end cartouche
742 @end iftex
743
744 16進数は、次のように指定します。
745
746 @iftex
747 @cartouche
748 @end iftex
749 @example
750 $ @command{dumpword '#0048'}
751  #0048:     72 = #0048 = 0000000001001000 = 'H'
752 @end example
753 @iftex
754 @end cartouche
755 @end iftex
756
757 @section CASL2ライブラリの使用
758
759 YACASL2の@file{as/casl2lib}ディレクトリには、CASL IIで記述されたライブラリファイルが格納されています。
760
761 このフォルダには、たとえば次のようなプログラムが含まれています。
762
763 @table @samp
764 @item OUTL
765 @file{outl.casl}。GR1に格納された値を、0〜65535の数値として出力します。
766
767 @item OUTA
768 @file{outa.casl}。GR1に格納された値を、-32767〜32767の数値として出力します。
769
770 @item MULL
771 @file{mull.casl}。GR1とGR2に格納された値を0〜65535の整数と見なし、積をGR3に格納します。
772
773 @item DIVL
774 @file{divl.casl}。GR1とGR2に格納された値を0〜65535の整数と見なし、商をGR3、剰余をGR0に格納します。
775 @end table
776
777 @subsection 数値を出力する
778
779 3と1の和を求める@file{addl.casl}で演算結果を出力するには、まず@file{addl.casl}を編集します。CASL IIの@command{CALL}命令で@command{OUTL}を副プログラムとして呼び出すようにします。
780
781 @iftex
782 @cartouche
783 @end iftex
784 @example
785 $ @command{cat addl_outl.casl}
786 MAIN    START
787         LD      GR1,A
788         ADDL    GR1,B
789         @strong{CALL    OUTL}
790         RET
791 A       DC      3
792 B       DC      1
793         END
794 @end example
795 @iftex
796 @end cartouche
797 @end iftex
798
799 変更したら@command{casl2}を、複数のファイルを指定して実行します。
800
801 @iftex
802 @cartouche
803 @end iftex
804 @example
805 $ @command{casl2 addl_outl.casl ~/yacasl2/as/casl2lib/outl.casl}
806 4
807 @end example
808 @iftex
809 @end cartouche
810 @end iftex
811
812 @node YACASL2コマンドマニュアル,, YACASL2の使い方, Top
813 @chapter YACASL2コマンドマニュアル
814
815 @cindex YACASL2コマンドマニュアル
816
817 YACASL2のコマンドとオプションについて解説します。
818
819 @menu
820 * casl2::
821 * comet2::
822 * dumpword::
823 @end menu
824
825 @node casl2
826 @section @command{casl2}
827
828 @pindex casl2
829 @cindex casl2
830
831 @command{casl2}は、引数として指定されたCASLファイルをアセンブルし、仮想マシンCOMET II上で実行します。CASLファイルは、アセンブラ言語CASL IIで記述されたテキストファイルです。引数が指定されない場合は、エラーメッセージを表示して終了します。
832
833 @example
834 $ @command{casl2 hello.casl}
835 @end example
836
837 副プログラムを呼び出す場合は、複数のCASLファイルを指定することもできます。
838
839 @example
840 $ @command{casl2 addl_outl.casl ~/yacasl2/as/casl2lib/outl.casl}
841 @end example
842
843 @unnumberedsubsec オプション
844
845 @command{casl2}は、次のオプションを指定できます。
846
847 @table @samp
848 @item -s
849 @itemx --source
850 CASLファイルの内容を表示します。
851
852 @item -l
853 @itemx --label
854 ラベルの一覧を表示し、ほかの作業を続行します。
855
856 @item -L
857 @itemx --labelonly
858 ラベルの一覧を表示して終了します。
859
860 @item -a
861 @itemx --assembledetail
862 アセンブル詳細結果を表示し、ほかの作業を続行します。
863
864 @item -A
865 @itemx --show-all
866 アセンブル詳細結果を表示して終了します。
867
868 @item -o<OBJECTFILE>
869 @itemx --assembleout
870 アセンブル結果をオブジェクトファイル@file{<OBJECTFILE>}に出力し、ほかの作業を続行します。出力されたオブジェクトファイルは、@command{comet2}で実行できます。オブジェクトファイルを指定しない場合、出力先は@file{a.o}です。オブジェクトファイルは1つだけ指定できます。
871
872 @item -O<OBJECTFILE>
873 @itemx --assembleoutonly
874 アセンブル結果をオブジェクトファイル@file{<OBJECTFILE>}に出力し、終了します。出力されたオブジェクトファイルは、@command{comet2}で実行できます。オブジェクトファイルを指定しない場合、出力先は@file{a.o}です。オブジェクトファイルは1つだけ指定できます。
875
876 @item -t
877 @itemx --trace
878 @itemx --tracearithmetic
879 実行時のレジスタをトレースします。レジスタには、GR0〜GR7という8個の汎用レジスタと、SP(スタックポインタ)、PR(プログラムレジスタ)、FR(フラグレジスタ)があります。レジストリの内容は、-32,768〜32,767の範囲の整数、#0000〜#FFFFの範囲の16進数、2進数で表示されます。文字の組に該当する場合は、「 = 」のうしろに文字が表示されます。-32768〜32767の範囲の整数を表示するので、算術演算の結果を確認する場合に使えます。
880
881 @item -T
882 @itemx --tracelogical
883 @option{-t}と同じく、実行時のレジスタをトレースします。@option{-t}と異なり0〜65,535の範囲の整数を表示するので、論理演算の結果を確認する場合に使えます。
884
885 @item -d
886 @itemx --dump
887 メモリの内容をすべて表示します。
888
889 @item -M <MEMORYSIZE>
890 @itemx --memorysize <MEMORYSIZE>
891 アセンブルおよび実行時のメモリサイズ@option{<MEMORYSIZE>}を0〜65,535の範囲で指定します。指定しない場合、メモリサイズは512です。
892
893 @item -C <CLOCKS>
894 @itemx --clocks <CLOCKS>
895 実行時のクロック周波数@option{<CLOCKS>}を0より大きい整数で指定します。指定しない場合、クロック周波数は5000000です。
896
897 @item -h
898 @itemx --help
899 @command{casl2}の使用方法を表示して終了します。
900 @end table
901
902 @node comet2
903 @section @command{comet2}
904
905 @pindex comet2
906 @cindex comet2
907
908 @command{comet2}は、引数として指定されたオブジェクトファイルを仮想マシンCOMET II上で実行します。オブジェクトファイルは、@command{casl}に@option{-o}または@option{-O}を指定して出力します。
909
910 @example
911 $ @command{comet2 hello.o}
912 @end example
913
914 引数で指定できるオブジェクトファイルは1つだけです。引数が指定されない場合は、エラーメッセージを表示して終了します。複数の引数を指定した場合、2番目以降の引数は無視されます。
915
916 @unnumberedsubsec オプション
917
918 @command{comet2}は、次のオプションを指定できます。
919
920 @table @samp
921
922 @item -t
923 @itemx --trace
924 @itemx --tracearithmetic
925 実行時のレジスタをトレースします。レジスタには、GR0〜GR7という8個の汎用レジスタと、SP(スタックポインタ)、PR(プログラムレジスタ)、FR(フラグレジスタ)があります。レジストリの内容は、-32,768〜32,767の範囲の整数、#0000〜#FFFFの範囲の16進数、2進数で表示されます。文字の組に該当する場合は、「 = 」のうしろに文字が表示されます。-32768〜32767の範囲の整数が表示されるので、算術演算の結果を確認する場合に使えます。
926
927 @item -T
928 @itemx --tracelogical
929 @option{-t}と同じく、実行時のレジスタをトレースします。@option{-t}と異なり0〜65,535の範囲の整数を表示するので、論理演算の結果を確認する場合に使えます。
930
931 @item -d
932 @itemx --dump
933 メモリの内容をすべて表示します。
934
935 @item -M <MEMORYSIZE>
936 @itemx --memorysize <MEMORYSIZE>
937 実行時のメモリサイズ@option{<MEMORYSIZE>}を0〜65,535の範囲で指定します。指定しない場合、メモリサイズは512です。
938
939 @item -C <CLOCKS>
940 @itemx --clocks <CLOCKS>
941 実行時のクロック周波数@option{<CLOCKS>}を0より大きい整数で指定します。指定しない場合、クロック周波数は5,000,000です。
942
943 @item -h
944 @itemx --help
945 @command{comet2}の使用方法を表示して終了します。
946 @end table
947
948 @node dumpword
949 @section @command{dumpword}
950
951 @pindex dumpword
952 @cindex dumpword
953
954 @command{dumpword}は、引数として指定された数値を、整数、#0000〜#FFFFの範囲の16進数、2進数で表示します。文字の組に該当する場合は、「 = 」のうしろに文字が表示されます。引数は、10進数または先頭に「#」の付いた16進数で指定します。表示される整数は、オプションにより-32,768〜32,767または0〜65,535の範囲です。オプションなしの場合は、-32,768〜32,767です。
955
956 @example
957 $ @command{dumpword 10}
958 @end example
959
960 引数で指定できる1つだけです。引数が指定されない場合は、使い方を表示して終了します。複数の引数を指定した場合、2番目以降の引数は無視されます。
961
962 @unnumberedsubsec オプション
963
964 @command{dumpword}は、次のオプションを指定できます。
965
966 @table @samp
967
968 @item -a
969 @itemx --arithmetic
970 出力される整数の範囲を-32,768〜32,767にします。オプションなしの場合と同じです。
971
972 @item -l
973 @itemx --logical
974 出力される整数の範囲を0〜65,535にします。
975
976 @item -h
977 @itemx --help
978 @command{dumpword}の使用方法を表示して終了します。
979 @end table
980
981 @bye