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