root/doc/manual.texi

/* [<][>][^][v][top][bottom][index][help] */
\input texinfo   @c -*-texinfo-*-
@c %**start of header
@ifnottex
@documentlanguage ja_JP
@end ifnottex
@setfilename yacasl2.info
@documentencoding UTF-8
@settitle YACASL2 - CASL II 処理システム
@firstparagraphindent insert
@paragraphindent 1
@ifhtml
@exampleindent 0
@end ifhtml
@c %**end of header

@copying
Copyright @copyright{} 2010-2026 j8takagi
@end copying

@dircategory Programming
@direntry
* YACASL2: (yacasl2.info).                          CASL II 処理システム
* casl2: (yacasl2.info)casl2 invocation.            casl2
* comet2: (yacasl2.info)comet2 invocation.          comet2
* dumpword: (yacasl2.info)dumpword invocation.      dumpword
* comet2monitor: (yacasl2.info)comet2monitor-invocation. comet2monitor
@end direntry

@titlepage
@title YACASL2
@subtitle コマンドラインインターフェイスで動作するオープンソースのCASL II処理システム
@author j8takagi
@insertcopying
@end titlepage

@node Top, Overview, (dir), (dir)
@ifhtml
@top YACASL2 - CASL II 処理システム
@end ifhtml

@menu
* Overview::                    YACASL2の概要
* Sample usage::                YACASL2の使用例
* casl2 invocation::            casl2
* comet2 invocation::           comet2
* dumpword invocation::         dumpword
* comet2monitor-invocation::    comet2monitor

@detailmenu
 --- The Detailed Node Listing ---

YACASL2の使用例

* Simple output::               実行結果の出力だけを表示
* Assemble result::             アセンブル結果の確認
* Register and memory::         実行時のレジスタとメモリを表示
* Only assemble::               アセンブルと実行を別に行う
* Analyze word::                1語の解析
* Use CASL2LIB::                CASL IIライブラリの使用

実行時のレジスタとメモリを表示

* Register specify::            特定のレジスタを表示
* End value::
* Step count::                  プログラムのステップ数を表示

@code{comet2monitor}

* comet2monitor options::       オプション
* monitor commands::            モニターコマンド
* comet2monitor examples::      使用例

@end detailmenu
@end menu

@contents

@node Overview, Sample usage, Top, Top
@chapter YACASL2の概要

YACASL2は、UNIXやLinuxのコマンドラインインターフェイスで
動作するオープンソースのCASL II処理システムです。
CASL IIは情報処理試験で用いられるアセンブラ言語で、
次の資料により仕様が公開されています。

@iftex
@cartouche
@end iftex
@quotation
@uref{https://www.ipa.go.jp/shiken/syllabus/ps6vr7000000i9g3-att/shiken_yougo_ver4_3.pdf, 情報処理技術者試験 情報処理安全確保支援士試験 試験で使用する情報技術に関する用語・プログラム言語など Ver 4.3}[PDFファイル] @*
別紙2 アセンブラ言語の仕様(5ページから12ページまで)
@end quotation
@iftex
@end cartouche
@end iftex

この資料の必要部分を抜粋し、HTMLとPDFに変換したもの

@iftex
@cartouche
@end iftex
@quotation
@uref{casl2_spec/casl2_spec.html, 情報処理技術者試験 アセンブラ言語の仕様(HTML版)}
@end quotation
@iftex
@end cartouche
@end iftex

@iftex
@cartouche
@end iftex
@quotation
@uref{casl2_spec/casl2_spec.pdf, 情報処理技術者試験 アセンブラ言語の仕様(PDF版)}
@end quotation
@iftex
@end cartouche
@end iftex

YACASL2は、CASL IIアセンブラ言語で記述されたファイルをアセンブルし、
仮想マシンCOMET II上で実行します。
アセンブルと実行は、連続で行うこともできますし、
アセンブル結果をファイルに保存してあとから実行することもできます。
YACASL2の動作はCASL IIの仕様に準拠しているため、情報処理試験の問題を
はじめ各種参考書やサイトに記載されたCASL IIのプログラムを
そのままアセンブルして実行できます。
また、本パッケージ中にCASL IIのサンプルプログラムが多数収録されています。

YACASL2は、「ふつうの処理系」として動作します。
YACASL2の操作は、端末上のコマンドラインインターフェイス(CLI)で操作します。
YACASL2は、次のような動作内容をすべてテキストで出力します。

@itemize @bullet

@item
ラベルとアドレスの対応

@item
アセンブル結果

@item
実行時のレジスタの内容

@item
実行時のメモリの内容
@end itemize

YACASL2では、機械コードモニターを使い、動作中のCPUやメモリーを調べたりデバッグしたりすることもできます。

また、出力された動作内容は、GNU/Linuxのさまざまなコマンド、
たとえば、@command{cat}、@command{less}、@command{grep}、@command{wc}などを使って解析できます。



@node Sample usage, casl2 invocation, Overview, Top
@chapter YACASL2の使用例
YACASL2 は、テキストファイルに記述されたCASLプログラムを処理します。
以下の例で用いられるCASLプログラムのファイルは、
テキストエディタなどで作成するか、インストールしたディレクトリの
中にある@file{as}ディレクトリからコピーしてください。

@menu
* Simple output::               実行結果の出力だけを表示
* Assemble result::             アセンブル結果の確認
* Register and memory::         実行時のレジスタとメモリを表示
* Only assemble::               アセンブルと実行を別に行う
* Analyze word::                1語の解析
* Use CASL2LIB::                CASL IIライブラリの使用
@end menu

@node Simple output, Assemble result, Sample usage, Sample usage
@section 実行結果の出力だけを表示

インストール時にコマンド実行の確認に使った@file{hello.casl}は、次のような内容です。
CASL IIのマクロ命令OUTは、文字列を出力します。

@example
$ @kbd{cat hello.casl}
MAIN     START
         OUT     OBUF,LEN
         RET
OBUF     DC      'Hello, World!'
LEN      DC      13
         END
@end example

次のコマンドを実行すると、CASL II のアセンブルと仮想マシン COMET II 上での実行が連続で行われ、文字列が出力されます。

@example
$ @kbd{casl2 hello.casl}
Hello, World!
@end example

@file{addl.casl}は、3と1の和を求めます。

@example
$ @kbd{cat addl.casl}
;;; ADDL r,adr
MAIN     START
         LD      GR1,A
         ADDL    GR1,B
         RET
A        DC      3
B        DC      1
         END
@end example

このプログラムには出力命令がないため、オプションなしで実行した場合には結果が出力されません。

@example
$ @kbd{casl2 addl.casl}
$
@end example

実行内容を確認するには、後述のようにCPU 内にあるレジスタやメモリの内容を表示するか、結果を出力するための処理を追加する必要があります。

@node Assemble result, Register and memory, Simple output, Sample usage
@section アセンブル結果の確認

casl2の処理途中で行われるアセンブルの結果を表示するには、オプション@option{-a}を指定します。
また、ラベルとアドレスの対応表を表示するには、オプション@option{-l}を指定します。

次のコマンドでは@file{hello.casl}の、ラベルとアドレスの対応表と、アセンブル結果と、実行結果が表示されます。
OUTはアセンブラ命令で複数の機械語命令で構成されているため、命令行1行に対して、複数行のコードが生成されます。

@example
$ @kbd{casl2 -a -l hello.casl}

Assemble hello.casl (0)

Label::::
MAIN.LEN ---> #0020
MAIN ---> #0000
MAIN.OBUF ---> #0013

Assemble hello.casl (1)
hello.casl:    1:MAIN    START
hello.casl:    2:        OUT     OBUF,LEN
    #0000   #7001
    #0001   #0000
    #0002   #7002
    #0003   #0000
    #0004   #1210
    #0005   #0013
    #0006   #1220
    #0007   #0020
    #0008   #F000
    #0009   #0002
    #000A   #1210
    #000B   #0021
    #0021   #000A
    #000C   #1220
    #000D   #0022
    #0022   #0001
    #000E   #F000
    #000F   #0002
    #0010   #7120
    #0011   #7110
hello.casl:    3:        RET
    #0012   #8100
hello.casl:    4:OBUF    DC      'Hello, World!'
    #0013   #0048
    #0014   #0065
    #0015   #006C
    #0016   #006C
    #0017   #006F
    #0018   #002C
    #0019   #0020
    #001A   #0057
    #001B   #006F
    #001C   #0072
    #001D   #006C
    #001E   #0064
    #001F   #0021
hello.casl:    5:LEN     DC      13
    #0020   #000D
hello.casl:    6:        END
Hello, World!
@end example

@file{addl.casl}の、ラベルとアドレスの対応表と、アセンブル結果は、次のようになります。

@example
$ @kbd{casl2 -a -l addl.casl}

Assemble addl.casl (0)

Label::::
MAIN ---> #0000
MAIN.A ---> #0007
MAIN.B ---> #0008
MAIN.C ---> #0009

Assemble addl.casl (1)
addl.casl:    1:;;; ADDL r,adr
addl.casl:    2:MAIN    START
addl.casl:    3:        LD      GR1,A
    #0000   #1010
    #0001   #0007
addl.casl:    4:        ADDL    GR1,B
    #0002   #2210
    #0003   #0008
addl.casl:    5:        ST      GR1,C
    #0004   #1110
    #0005   #0009
addl.casl:    6:        RET
    #0006   #8100
addl.casl:    7:A       DC      3
    #0007   #0003
addl.casl:    8:B       DC      2
    #0008   #0002
addl.casl:    9:C       DS      1
    #0009   #0000
addl.casl:   10:        END
@end example

なお、オプション@option{-A}を指定すると、アセンブル結果が表示される時点で処理が終了します。
仮想マシンCOMET IIでのプログラム実行はされません。

@node Register and memory, Only assemble, Assemble result, Sample usage
@section 実行時のレジスタとメモリを表示

YACASL2では実行中のCPUのレジスタとメモリの内容をそれぞれ、@option{-t}と@option{-d}を指定することで表示できます。

また、@option{-M}で、仮想マシンCOMET II のメモリ容量を語(16ビット)単位で指定できます。
小さいプログラムを実行するときは、メモリ容量を小さくすれば結果が見やすくなります。

@menu
* Register specify::            特定のレジスタを表示
* End value::
* Step count::                  プログラムのステップ数を表示
@end menu

@file{addl.casl}では、次のようにCPUのレジスタとメモリの内容を表示できます。

@example
$ @kbd{casl2 -t -d -M16 addl.casl | less}

Assemble addl.casl (0)

Assemble addl.casl (1)

Executing machine codes
#0000: Register::::
#0000: GR0:      0 = #0000 = 0000000000000000
#0000: GR1:      0 = #0000 = 0000000000000000
#0000: GR2:      0 = #0000 = 0000000000000000
#0000: GR3:      0 = #0000 = 0000000000000000
#0000: GR4:      0 = #0000 = 0000000000000000
#0000: GR5:      0 = #0000 = 0000000000000000
#0000: GR6:      0 = #0000 = 0000000000000000
#0000: GR7:      0 = #0000 = 0000000000000000
#0000: SP:      16 = #0010 = 0000000000010000
#0000: PR:       0 = #0000 = 0000000000000000
#0000: FR (OF SF ZF): 000
#0000: Memory::::
#0000: adr : 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
       -------------------------------------------------------------------------------------
#0000: 0000: 1010 0007 2210 0008 1110 0009 8100 0003 0002 0000 0000 0000 0000 0000 0000 0000

#0002: Register::::
#0002: GR0:      0 = #0000 = 0000000000000000
#0002: GR1:      3 = #0003 = 0000000000000011
#0002: GR2:      0 = #0000 = 0000000000000000
#0002: GR3:      0 = #0000 = 0000000000000000
#0002: GR4:      0 = #0000 = 0000000000000000
#0002: GR5:      0 = #0000 = 0000000000000000
#0002: GR6:      0 = #0000 = 0000000000000000
#0002: GR7:      0 = #0000 = 0000000000000000
#0002: SP:      16 = #0010 = 0000000000010000
#0002: PR:       2 = #0002 = 0000000000000010
#0002: FR (OF SF ZF): 000
#0002: Memory::::
#0002: adr : 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
       -------------------------------------------------------------------------------------
#0002: 0000: 1010 0007 2210 0008 1110 0009 8100 0003 0002 0000 0000 0000 0000 0000 0000 0000

#0004: Register::::
#0004: GR0:      0 = #0000 = 0000000000000000
#0004: GR1:      5 = #0005 = 0000000000000101
#0004: GR2:      0 = #0000 = 0000000000000000
#0004: GR3:      0 = #0000 = 0000000000000000
#0004: GR4:      0 = #0000 = 0000000000000000
#0004: GR5:      0 = #0000 = 0000000000000000
#0004: GR6:      0 = #0000 = 0000000000000000
#0004: GR7:      0 = #0000 = 0000000000000000
#0004: SP:      16 = #0010 = 0000000000010000
#0004: PR:       4 = #0004 = 0000000000000100
#0004: FR (OF SF ZF): 000
#0004: Memory::::
#0004: adr : 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
       -------------------------------------------------------------------------------------
#0004: 0000: 1010 0007 2210 0008 1110 0009 8100 0003 0002 0000 0000 0000 0000 0000 0000 0000

#0006: Register::::
#0006: GR0:      0 = #0000 = 0000000000000000
#0006: GR1:      5 = #0005 = 0000000000000101
#0006: GR2:      0 = #0000 = 0000000000000000
#0006: GR3:      0 = #0000 = 0000000000000000
#0006: GR4:      0 = #0000 = 0000000000000000
#0006: GR5:      0 = #0000 = 0000000000000000
#0006: GR6:      0 = #0000 = 0000000000000000
#0006: GR7:      0 = #0000 = 0000000000000000
#0006: SP:      16 = #0010 = 0000000000010000
#0006: PR:       6 = #0006 = 0000000000000110
#0006: FR (OF SF ZF): 000
#0006: Memory::::
#0006: adr : 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
       -------------------------------------------------------------------------------------
#0006: 0000: 1010 0007 2210 0008 1110 0009 8100 0003 0002 0005 0000 0000 0000 0000 0000 0000
@end example

@node Register specify, End value, Register and memory, Register and memory
@subsection 特定のレジスタを表示

@file{addl.casl}のレジスタやメモリの中で、実行中に値が変化しているのはGR1だけです。
こうした場合は、@command{grep}を使って表示される内容を絞り込むことで動作を検証しやすくなります。

@example
$ @kbd{casl2 -t addl.casl | grep 'GR1:'}
#0000: GR1:      0 = #0000 = 0000000000000000
#0002: GR1:      3 = #0003 = 0000000000000011
#0004: GR1:      5 = #0005 = 0000000000000101
#0006: GR1:      5 = #0005 = 0000000000000101
@end example

この内容を、先に出力したアセンブル結果と比較してください。
次の表のように、PRとGR1、命令行が対応していることがわかります。

@multitable @columnfractions .3 .3 .4
@item PR @tab GR1 @tab 命令行
@item #0000
@tab #0000
@tab (なし)
@item #0002
@tab #0003
@tab @code{LD GR1,A}
@item #0004
@tab #0004
@tab @code{ADDL GR1,B}
@item #0006
@tab #0006
@tab @code{ST GR1,C}
@end multitable

@node End value, Step count, Register specify, Register and memory
@subsection プログラム終了時の値を表示

@command{grep}と@command{tail}を組み合わせれば、プログラム終了時の値を表示できます。

@file{addl.casl}でプログラム終了時のGR1の値を確認するには、次のようにします。

@example
$ @kbd{casl2 -t addl.casl | grep 'GR1:' | tail -1}
#0006: GR1:      5 = #0005 = 0000000000000101
@end example

@file{sum_10.casl}は、1から10までの整数の和を求め、GR2に格納してからメモリにストア(書き込み)します。

@example
$ @kbd{cat sum_10.casl}
;;; sum_10.casl
;;; 1から10までの整数をすべて加算した値をメモリーに格納する
MAIN    START
        XOR     GR2,GR2         ; GR2を初期化
        LD      GR1,FST         ; GR1に初項をメモリーから転送
LOOP    ADDL    GR2,GR1         ; ループ先頭。GR2 <- GR2 + GR1
        ADDL    GR1,STEP        ; GR1 <- GR1 + 公差
        CPL     GR1,LST         ; GR1が末項より大きい場合は終了
        JPL     FIN             ; ↓
        JUMP    LOOP            ; ループ終端
FIN     ST      GR2,RST         ; GR2の結果をメモリーに転送
        RET
FST     DC      1               ; 初項
LST     DC      10              ; 末項
STEP    DC      1               ; 公差
RST     DS      1               ; 結果
        END
@end example

@file{sum_10.casl}でプログラム終了時のGR2の値を確認するには、次のようにします。

@example
$ @kbd{casl2 -t sum_10.casl | grep 'GR2:' | tail -1}
#000E: GR2:     55 = #0037 = 0000000000110111 = '7'
@end example

@node Step count,  , End value, Register and memory
@subsection プログラムのステップ数を表示

@command{grep}と@command{wc}を組み合わせれば、プログラムのステップ数を表示できます。

@example
$ @kbd{casl2 -t hello.casl | grep 'GR1:' | wc -l}
11
@end example

@example
$ @kbd{casl2 -t addl.casl | grep 'GR1:' | wc -l}
3
@end example

@file{sum_10.casl}はプログラム内にループがあるため、ステップ数が大きくなります。

@example
$ @kbd{casl2 -t sum_10.casl | grep 'GR2:' | wc -l}
53
@end example

@node Only assemble, Analyze word, Register and memory, Sample usage
@section アセンブルと実行を別に行う

@command{casl2}に@option{-O}@file{ファイル名}を指定すると、オブジェクトファイルを作成できます。

@example
$ @kbd{casl2 -Ohello.o hello.casl}
@end example

作成されたオブジェクトファイルの内容は、@command{od}を使って確認できます。
テキストファイルではないため、@command{cat}などでは確認できません。

@example
$ @kbd{od -t x2 hello.o}
0000000 7001 0000 7002 0000 1210 0013 1220 0020
0000020 f000 0002 1210 0021 1220 0022 f000 0002
0000040 7120 7110 8100 0048 0065 006c 006c 006f
0000060 002c 0020 0057 006f 0072 006c 0064 0021
0000100 000d 000a 0001
0000106
@end example

オブジェクトファイルの実行には、@command{comet2}を使います。

@example
$ @kbd{comet2 hello.o}
Hello, World!
@end example

@node Analyze word, Use CASL2LIB, Only assemble, Sample usage
@section 1語の解析

CASL IIでは、1語(1 word、16ビット)を単位としてデータが処理されます。
@command{dumpword}は、指定した1語を10進数、16進数、2進数で表示します。

@example
$ @kbd{dumpword 72}
    72:     72 = #0048 = 0000000001001000 = 'H'
@end example

@node Use CASL2LIB,  , Analyze word, Sample usage
@section CASL IIライブラリの使用

YACASL2の@file{as/casl2lib}ディレクトリには、CASL IIで記述されたライブラリファイルが格納されています。

このフォルダには、たとえば次のようなプログラムが含まれています。

@table @option
@item OUTL
@file{outl.casl}。
GR1に格納された値を、0以上65535以下の整数として出力します。

@item OUTA
@file{outa.casl}。
GR1に格納された値を、-32767以上32767以下の整数として出力します。

@item MULL
@file{mull.casl}。
GR1とGR2に格納された値を0以上65535以下の整数と見なし、積をGR3に格納します。

@item DIVL
@file{divl.casl}。
GR1とGR2に格納された値を0以上65535以下の整数と見なし、商をGR3、剰余をGR0に格納します。
@end table

@subsection 数値を出力する

3と1の和を求める@file{addl.casl}で演算結果を出力するには、まず@file{addl.casl}を編集します。
CASL IIの@command{CALL}命令で@command{OUTL}を副プログラムとして呼び出します。

@example
$ @kbd{cat addl_outl.casl}
MAIN    START
        LD      GR1,A
        ADDL    GR1,B
        @emph{CALL    OUTL}
        RET
A       DC      3
B       DC      1
        END
@end example

変更したら@command{casl2}を、複数のファイルを指定して実行します。

@example
$ @kbd{casl2 addl_outl.casl ~/yacasl2/as/casl2lib/outl.casl}
4
@end example

@node casl2 invocation, comet2 invocation, Sample usage, Top
@chapter @command{casl2}

@pindex casl2
@cindex casl2
@cindex invoking
@cindex options
@cindex usage
@cindex help

@command{casl2}は、引数として指定されたCASLファイルをアセンブルし、仮想マシンCOMET II上で実行します。
CASLファイルは、アセンブラ言語CASL IIで記述されたテキストファイルです。
引数が指定されない場合は、エラーメッセージを表示して終了します。

@example
$ @kbd{casl2 hello.casl}
@end example

複数のCASLファイルを指定することで、副プログラムを呼び出すこともできます。

@example
$ @kbd{casl2 addl_outl.casl ~/yacasl2/as/casl2lib/outl.casl}
@end example

@unnumberedsec オプション

@command{casl2}は、次のオプションを指定できます。

@table @option
@item -s
@itemx --source
CASLファイルの内容を表示します。

@item -l
@itemx --label
ラベルの一覧を次の形式で表示します。
表示後、ほかの作業を続行します。

@example
<プログラム名>.<ラベル名> ---> <アドレスの16進数表現>
@end example

@item -L
@itemx --labelonly
@option{-l}と同じ形式でラベルの一覧を表示します。
表示後、ほかの作業は続行せず、終了します。

@item -a
@itemx --assembledetail
アセンブル詳細結果を表示し、ほかの作業を続行します。

@item -A
@itemx --assembledetailonly
アセンブル詳細結果を表示して終了します。

@item -o<OBJECTFILE>
@itemx --assembleout<OBJECTFILE>
アセンブル結果をオブジェクトファイル@file{<OBJECTFILE>}に出力し、ほかの作業を続行します。
出力されたオブジェクトファイルは、@command{comet2}で実行できます。
オブジェクトファイルを指定しない場合、出力先は@file{a.o}です。
オブジェクトファイルは1つだけ指定できます。

@item -O[<OBJECTFILE>]
@itemx --assembleoutonly[<OBJECTFILE>]
アセンブル結果をオブジェクトファイル@file{<OBJECTFILE>}に出力し、終了します。
出力されたオブジェクトファイルは、@command{comet2}で実行できます。
オブジェクトファイルを指定しない場合、出力先は@file{a.o}です。
オブジェクトファイルは1つだけ指定できます。

@item -t
@itemx --trace
@itemx --tracearithmetic
プログラム実行中のレジスタの値を次の形式で表示します。

@example
<PR値の16進数表現>: <レジスタ>: <値の10進数表現> =
<値の16進数表現> = <値の2進数表現>[ ='文字']
@end example

@itemize
@item
@code{<PR値の16進数表現>}と@code{<レジスタ>}、@code{<値の16進数表現>}は、4けたの16進数で表されます。
@code{<PR値の16進数表現>}と@code{<値の16進数表現>}には、先頭に@code{#}が付きます。
範囲は@code{#0000}から@code{#FFFF}です

@item
@code{<値の10進数表現>}は符号の付いた10進数です。
範囲は-32768から32767です。

@item
@code{<値の2進数表現>}は、16けたの2進数で表されます。
範囲は、@code{0000000000000000}から@code{1111111111111111}です

@item
@code{[ ='文字']}は、レジストリの値が「文字の組」の範囲に含まれる場合に表示されます。
@end itemize

表示されるレジスタには、次の種類があります。

@table @code
@item GR0 GR1 GR2 GR3 GR4 GR5 GR6 GR7
汎用レジスタ

@item SP
スタックポインタ

@item PR
プログラムレジスタ

@item FR
フラグレジスタ
@end table

例えば、次のように表示されます。

@example
#0002: GR1:      3 = #0003 = 0000000000000011
@end example

@item -T
@itemx --tracelogical
@option{-t}と同じように、プログラム実行中のレジスタの値を表示します。
ただし@option{-t}と異なり、@code{<値の10進数表現>}は符号の付かない10進数です。
値の範囲は0から65535です。

@item -d
@itemx --dump
メモリの内容をすべて表示します。

@item -M <MEMORYSIZE>
@itemx --memorysize <MEMORYSIZE>
アセンブルおよびCOMET II実行時のメモリサイズ@option{<MEMORYSIZE>}をWORD(16ビット)単位で1から65535の範囲で指定します。指定しない場合、512語です。小さいプログラムを実行するときは、メモリ容量を小さくすれば結果が見やすくなります。

@item -C <CLOCKS>
@itemx --clocks <CLOCKS>
COMET II実行時のクロック周波数@option{<CLOCKS>}を0より大きい整数で指定します。
指定しない場合、クロック周波数は5000000です。

@item -v
@itemx --version
@command{casl2}のバージョンを表示して終了します。

@item -h
@itemx --help
@command{casl2}の使用方法を表示して終了します。
@end table

@node comet2 invocation, dumpword invocation, casl2 invocation, Top
@chapter @command{comet2}

@pindex comet2
@cindex comet2
@cindex invoking
@cindex options
@cindex usage
@cindex help

@command{comet2}は、引数として指定されたオブジェクトファイルを仮想マシンCOMET II上で実行します。
オブジェクトファイルは、@command{casl}に@option{-o}または@option{-O}を指定して出力します。

@example
$ @kbd{comet2 hello.o}
@end example

引数で指定できるオブジェクトファイルは1つだけです。
引数が指定されない場合は、エラーメッセージを表示して終了します。
複数の引数を指定した場合、2番目以降の引数は無視されます。

@unnumberedsec オプション

@command{comet2}は、次のオプションを指定できます。

@table @option

@item -t
@itemx --trace
@itemx --tracearithmetic
プログラム実行中のレジスタの値を次の形式で表示します。
@code{<値の10進数表現>}は符号の付いた10進数です。
範囲は-32768から32767です。

@example
<PR値の16進数表現>: <レジスタ>: <値の10進数表現> = <値の16進数表現> = <値の2進数表現>[ ='文字']
@end example

@itemize
@item
@code{<PR値の16進数表現>}と@code{<値の16進数表現>}は、先頭に@code{#}が付いた4けたの16進数で表されます。
範囲は、@code{#0000}から@code{#FFFF}です

@item
@code{<値の2進数表現>}は、16けたの2進数で表されます。
範囲は、@code{0000000000000000}から@code{1111111111111111}です

@item
@code{[ ='文字']}は、レジストリの値が「文字の組」の範囲に含まれる場合に表示されます。
@end itemize

例えば、次のように表示されます。

@example
#0002: GR1:      3 = #0003 = 0000000000000011
@end example

表示されるレジスタには、次の種類があります。

@table @code
@item GR0 GR1 GR2 GR3 GR4 GR5 GR6 GR7
汎用レジスタ

@item SP
スタックポインタ

@item PR
プログラムレジスタ

@item FR
フラグレジスタ
@end table

@item -T
@itemx --tracelogical
@option{-t}と同じように、プログラム実行中のレジスタの値を表示します。
ただし、@option{-t}と異なり、@code{<値の10進数表現>}は符号の付かない10進数です。
値の範囲は0から65535です。

@item -d
@itemx --dump
メモリの内容をすべて表示します。

@item -M <MEMORYSIZE>
@itemx --memorysize <MEMORYSIZE>
COMET II実行時のメモリサイズ@option{<MEMORYSIZE>}をWORD(16ビット)単位で1から65535の範囲で指定します。指定しない場合、512語です。小さいプログラムを実行するときは、メモリ容量を小さくすれば結果が見やすくなります。

@item -C <CLOCKS>
@itemx --clocks <CLOCKS>
実行時のクロック周波数@option{<CLOCKS>}を0より大きい整数で指定します。
指定しない場合、5000000です。

@item -v
@itemx --version
@command{comet2}のバージョンを表示して終了します。

@item -h
@itemx --help
@command{comet2}の使用方法を表示して終了します。
@end table

@node dumpword invocation, comet2monitor-invocation, comet2 invocation, Top
@chapter @command{dumpword}

@pindex dumpword
@cindex dumpword
@cindex invoking
@cindex options
@cindex usage
@cindex help

@command{dumpword}は引数として指定された数値を、整数、#0000から#FFFFまでの範囲の16進数、2進数で表示します。
文字の組に該当する場合は、「 = 」のうしろに文字が表示されます。
引数は、10進数または先頭に「#」の付いた16進数で指定します。
表示される整数は、オプションにより符号付きか符号なしかを指定します。
オプションなしの場合は符号付きです。
整数の範囲は、符号付きの場合は-32768以上32767以下、符号なしの場合は0以上65535以下です。

@example
$ @kbd{dumpword 10}
    10:     10 = #000A = 0000000000001010 = '\n'
@end example

引数が指定されない場合は、使い方を表示して終了します。
複数の引数を指定した場合、1つ目の引数だけが表示され、2つ目以降の引数は無視されます。

@unnumberedsec 注意

マイナスの数や16進数はシェルの仕様により、そのままでは指定できません。

マイナスの数を指定するときは、次のように@option{--}を付けます。

@example
$ @kbd{dumpword -- -72}
   -72:    -72 = #FFB8 = 1111111110111000
@end example

先頭に「#」を付けて16進数を指定するときは、次のように「'」で囲みます。

@example
$ @kbd{dumpword '#0048'}
 #0048:     72 = #0048 = 0000000001001000 = 'H'
@end example

@unnumberedsec オプション

@command{dumpword}は、次のオプションを指定できます。

@table @option

@item -a
@itemx --arithmetic
出力される整数の範囲を-32,768以上32,767以下にします。
オプションなしの場合と同じです。

@item -l
@itemx --logical
出力される整数の範囲を0以上65,535以下にします。

@item -v
@itemx --version
@command{dumpword}のバージョンを表示して終了します。

@item -h
@itemx --help
@command{dumpword}の使用方法を表示して終了します。
@end table

@node comet2monitor-invocation,  , dumpword invocation, Top
@chapter @command{comet2monitor}

@pindex comet2monitor
@cindex comet2monitor
@cindex invoking
@cindex options
@cindex usage
@cindex help

@command{comet2monitor}は、COMET II機械コードモニターです。
オブジェクトファイルをロードし、対話的にステップ実行・逆アセンブル・レジスタやメモリの確認ができます。

@example
comet2monitor [-tTdqvh] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE
@end example

@menu
* comet2monitor options::       オプション
* monitor commands::            モニターコマンド
* comet2monitor examples::      使用例
@end menu

@node comet2monitor options, monitor commands, comet2monitor-invocation, comet2monitor-invocation
@section オプション

@table @option
@item -t
@itemx --trace
@itemx --tracearithmetic
命令実行ごとにCPUレジスタの内容を表示します。
値は算術(符号あり)表現で表示されます。

@item -T
@itemx --tracelogical
命令実行ごとにCPUレジスタの内容を表示します。
値は論理(符号なし)表現で表示されます。

@item -d
@itemx --dump
命令実行ごとにメモリダンプを表示します。

@item -q
逆アセンブルの自動表示をOFFにします。
デフォルトでは逆アセンブル自動表示はONです。

@item -M @var{MEMORYSIZE}
@itemx --memorysize=@var{MEMORYSIZE}
COMET II実行時のメモリサイズ@option{<MEMORYSIZE>}をWORD(16ビット)単位で1から65535の範囲で指定します。指定しない場合、512語です。小さいプログラムを実行するときは、メモリ容量を小さくすれば結果が見やすくなります。

@item -C @var{CLOCKS}
@itemx --clocks=@var{CLOCKS}
COMET II実行時のクロック周波数@option{<CLOCKS>}を0より大きい整数で指定します。
指定しない場合、5000000です。

@item -v
@itemx --version
バージョン情報を表示して終了します。

@item -h
@itemx --help
使い方を表示して終了します。
@end table

@node monitor commands, comet2monitor examples, comet2monitor options, comet2monitor-invocation
@section モニターコマンド

@code{comet2monitor}は起動後、対話的にコマンドを受け付けます。
コマンドは省略形でも指定できます。
空行を入力すると、直前のコマンドをリピートします。
@code{!}で始まる入力はシェルコマンドとして実行されます。

@subsection 実行コマンド

@table @code
@item n
@itemx next
現在のPRアドレスの命令を1つ実行します。
実行後、レジスタ・メモリ・逆アセンブルが自動表示設定に従い表示されます。

@item c
@itemx continue
プログラムが終了するか、ブレークポイントに達するまで実行します。
実行中、各ステップで逆アセンブルが自動表示設定に従い表示されます。
@end table

@subsection 表示コマンド

@table @code
@item r
@itemx reverse
メモリを逆アセンブルして表示します。
引数なしではロードされたプログラム全体を表示します。

@example
r @var{start} @var{end}
@end example

アドレスを指定した場合は、@var{start}から@var{end}の範囲を表示します。
アドレスは10進数または16進数(@code{#xxxx}形式)で指定できます。

@example
r auto
r noauto
@end example

@code{auto}または@code{a}を指定すると逆アセンブルの自動表示をONに、
@code{noauto}または@code{n}を指定するとOFFにします。

@item t
@itemx trace
CPUレジスタの内容を算術(符号あり)表現で表示します。

@example
t auto
t noauto
@end example

@code{auto}または@code{a}を指定するとレジスタの自動表示をONに、
@code{noauto}または@code{n}を指定するとOFFにします。

@item T
@itemx Trace
CPUレジスタの内容を論理(符号なし)表現で表示します。
@code{auto}/@code{noauto}の指定は@code{t}と同様です。

@item d
@itemx dump
メモリダンプを表示します。
引数なしでは@code{#0000}から@code{#0040}の範囲を表示します。
メモリサイズが@code{#0040}より小さい場合はメモリ全体を表示します。

@example
d @var{start}
d @var{start} @var{end}
d @var{start} +@var{length}
@end example

@var{start}のみ指定した場合は@var{start}から@code{#0040}語分、
@var{end}も指定した場合は@var{start}から@var{end}の範囲を表示します。
@code{+}を付けた場合は@var{start}から@var{length}語分を表示します。

@example
d auto
d noauto
@end example

@code{auto}または@code{a}を指定するとメモリダンプの自動表示をONに、
@code{noauto}または@code{n}を指定するとOFFにします。
@end table

@subsection ブレークポイントコマンド

@table @code
@item b add @var{address}
@itemx break add @var{address}
@var{address}にブレークポイントを追加します。

@item b del @var{address}
@itemx break del @var{address}
@var{address}のブレークポイントを削除します。

@item b list
@itemx break list
設定中のブレークポイント一覧を表示します。

@item b reset
@itemx break reset
すべてのブレークポイントを削除します。
@end table

@subsection その他のコマンド

@table @code
@item l @var{filepath} [@var{address}]
@itemx load @var{filepath} [@var{address}]
@var{filepath}のオブジェクトファイルをメモリにロードします。
@var{address}を省略した場合は@code{#0000}番地にロードします。

@item reset
CPUをリセットします。メモリの内容は保持されます。

@item resetall
CPUとメモリをリセットします。

@item q
@itemx quit
モニターを終了します。

@item ?
@itemx h
@itemx help
コマンドのヘルプを表示します。

@item !@var{command}
シェルコマンド@var{command}を実行します。
@end table

@node comet2monitor examples,  , monitor commands, comet2monitor-invocation
@section 使用例

@file{ldlad.o}をオプションなしで起動し、ステップ実行します。
デフォルトで逆アセンブルの自動表示がONのため、起動時にプログラム全体の逆アセンブル結果と、
最初に実行される命令が表示されます。

@example
$ @kbd{comet2monitor -M32 as/sample/ldlad.o}
        LAD     GR1,#0001       ; #0000: #1210 #0001
        LAD     GR2,#000B       ; #0002: #1220 #000B
        LD      GR3,#000B       ; #0004: #1030 #000B
        ST      GR2,#000C       ; #0006: #1120 #000C
        ST      GR3,#000C,GR1   ; #0008: #1131 #000C
        RET                     ; #000A: #8100
        DC      3               ; #000B: #0003 ::     3 = #0003 = 0000000000000011
        DC      0               ; #000C: #0000 ::     0 = #0000 = 0000000000000000
        DC      0               ; #000D: #0000 ::     0 = #0000 = 0000000000000000
        DC      0               ; #000E: #0000 ::     0 = #0000 = 0000000000000000
#0000: Disassemble::::        LAD     GR1,#0001       ; #0000: #1210 #0001

COMET II machine code monitor. Type ? for help.
(comet2 monitor) n
> n
#0002: Disassemble::::        LAD     GR2,#000B       ; #0002: #1220 #000B

(comet2 monitor) n
> n
#0004: Disassemble::::        LD      GR3,#000B       ; #0004: #1030 #000B

(comet2 monitor) q
> q
Quit: COMET II monitor
@end example

レジスタトレースとメモリダンプを追加して起動する場合は@option{-T}と@option{-d}を指定します。

@example
$ @kbd{comet2monitor -Td -M32 as/sample/ldlad.o}
@end example

逆アセンブルの自動表示をOFFにして最後まで一気に実行する場合は、
モニター起動後に@code{r noauto}を実行してから@code{c}を使います。

@example
(comet2 monitor) r noauto
> r noauto
(comet2 monitor) c
> c
Return to top.
@end example

@bye

/* [<][>][^][v][top][bottom][index][help] */