Tatara

第31章
長いシンボル名と
大文字・小文字を区別する名前

TATARAのシンボルの名前は必要なだけ長くでき、そのすべての文字が意味を持ちます。/Cを付けると、大文字と小文字の違いも意味を持ちます(7章)。この章では、A:\TATARA\EXAMPLES\NAMESにある例、NAMESを作ります。1つのソースでその両方を示す例です。そのあとで、長いシンボル名と/Cを1つのソースの外に広げ、複数のモジュールからなるプログラムで使います。最後に、/Cがマクロの名前にどう働くかを見ます。

31.1 この例

NAMESはプログラムを作りません。そのBUILD.BATは、1つのソースを/Cなしと/C付きで2回アセンブルし、それぞれのシンボル表をテキスト・ファイルに残します。この2つのファイルが結果で、TATARAがどの名前を1つとして、どの名前を2つとして扱ったかがわかります。

31.2 ソース

; NAMES.AS - names as long as you like, in either case. 
; 
; A SYMBOL MAY BE 255 CHARACTERS AND ALL OF THEM COUNT. M80 keeps the 
; first six, which is why so much CP/M-era assembly is written in 
; abbreviations. The two names below differ only in their last five 
; characters and are two different symbols here. 255 is the limit, and 
; the test suite has a 240-character name in it; these are 48, which is 
; as long as a line can carry and still be read on an MSX screen. 
 
first_pass_symbol_table_high_water_mark_in_bytes        defl    1024 
first_pass_symbol_table_high_water_mark_in_words        defl    512 
 
; THE SAME SIX LETTERS IN TWO CASES. Without /C they are ONE symbol, 
; and the second line changes its value. With /C they are TWO, with 
; values 1 and 2. The symbol table of each run says which - and DEFL 
; is used rather than EQU because a redefinition is legal, so the 
; source assembles cleanly in both modes. 
 
Counter         defl    1 
counter         defl    2 
 
; DIRECTIVES, MNEMONICS AND REGISTER NAMES ARE CASE-INSENSITIVE IN 
; BOTH MODES. /C is about the names you choose, not the ones the Z80 
; already has. 
 
                cseg 
 
start:          LD      A,1 
                ld      b,a 
                DB      Counter 
                db      counter 
                ret 
 
                end     start   

ソースは3つの部分からなります。

31.3 作る

rem BUILD.BAT - EXAMPLE: NAMES 
rem 
rem One source, assembled twice, and the two symbol tables are the 
rem answer. 
rem 
rem   /S   print the symbol table when the assembly ends 
rem   /P   assemble to the screen, producing no object file 
rem   /C   make symbol and macro names case-SENSITIVE 
rem 
rem Without /C, Counter and counter are one symbol whose value ends up 
rem 2, and the table has one entry. With /C they are two symbols, 1 
rem and 2, and the table has both. The default is M80s behaviour. 
rem 
rem The two long names are 48 characters each and differ in the last 
rem five. M80 would have made them one symbol. 
 
echo === Case-insensitive, which is the default 
tatara /q /p /s names.as > insens.txt 
 
echo === Case-sensitive 
tatara /q /p /c /s names.as > sens.txt 
 
echo === Done. Compare INSENS.TXT with SENS.TXT.
 

/Pはリスティングを画面に表示し、/Sはそのあとにシンボル表を表示します(5.5節、19章)。コマンド・ラインにオブジェクト・ファイルの名前がないので、オブジェクト・ファイルは書き出されません。それぞれの>は、TATARAが表示する内容をファイルに送ります。この例はインクルード・ファイルを使わないので、バッチ・ファイルはTATARAを設定しません。

A:\TATARA\EXAMPLES\NAMES>build 
=== Case-insensitive, which is the default 
=== Case-sensitive 
=== Done. Compare INSENS.TXT with SENS.TXT.
 

31.4 2つのファイルを読む

どちらのファイルも、ページの見出しと、書いたとおりのソースからなるリスティングで始まります。/Lがないので、リスティングにはアドレスもバイトもありません。そのあとにシンボル表が続きます。INSENS.TXTのシンボル表全体は次のとおりです。

ASEG - absolute 
 
0002h  var        Counter 
0200h  var        first_pass_symbol_table_high_water_mark_in_words 
0400h  var        first_pass_symbol_table_high_water_mark_in_bytes 
 
CSEG - default code segment, 0006h bytes 
 
0000h             start 
 
DSEG - default data segment, 0000h bytes 
 
(no symbols)
 

SENS.TXTのシンボル表は次のとおりです。

ASEG - absolute 
 
0001h  var        Counter 
0002h  var        counter 
0200h  var        first_pass_symbol_table_high_water_mark_in_words 
0400h  var        first_pass_symbol_table_high_water_mark_in_bytes 
 
CSEG - default code segment, 0006h bytes 
 
0000h             start 
 
DSEG - default data segment, 0000h bytes 
 
(no symbols)
 

2つの長いシンボル名は、どちらのファイルでも2つのシンボルです。/Cの有無にかかわらず、名前のすべての文字が意味を持ちます。2つのファイルが違うのはCounterだけで、図31.1のとおりです。

PIC

図 31.1: 2つのシンボル表のアブソリュートのセクション。

コードは、どちらの実行でも同じ6バイトです。/Cなしでは、db Counterとdb counterはどちらも2で、/C付きでは 1と2です。

31.5 モジュールをまたぐ長いシンボル名

名前はオブジェクト・ファイルの中でも長さをすべて保ち(7.2節)、TANRENはその全体で照合します。LONGUSE.ASは、NAMES.ASの2つの長いシンボル名を外部の名前として使います。

; LONGUSE.AS - uses two long names from another module. 
                extrn   first_pass_symbol_table_high_water_mark_in_bytes 
                extrn   first_pass_symbol_table_high_water_mark_in_words 
                cseg 
                ld      hl,first_pass_symbol_table_high_water_mark_in_bytes 
                ld      de,first_pass_symbol_table_high_water_mark_in_words 
                ret 
                end
 

LONGDEF1.ASは、そのうち最初の名前だけを定義します。

; LONGDEF1.AS - defines only the first of the two. 
                public  first_pass_symbol_table_high_water_mark_in_bytes 
                cseg 
first_pass_symbol_table_high_water_mark_in_bytes: 
                nop 
                end
 

2つの名前は最初の43文字が同じですが、TANRENは一方を他方と取り違えません。足りない名前は、すべての文字で表示されます。

A:\TATARA\EXAMPLES\NAMES>tatara /q longuse.as longuse.tro 
A:\TATARA\EXAMPLES\NAMES>tatara /q longdef1.as longdef1.tro 
A:\TATARA\EXAMPLES\NAMES>tanren longuse longdef1 /o:l1.com 
... 
Never defined: 
  first_pass_symbol_table_high_water_mark_in_words 
ERROR: the symbols above were never defined.
 

LONGDEF2.ASは、それぞれをnop付きのラベルとして、両方を定義します。

; LONGDEF2.AS - defines both. 
                public  first_pass_symbol_table_high_water_mark_in_bytes 
                public  first_pass_symbol_table_high_water_mark_in_words 
                cseg 
first_pass_symbol_table_high_water_mark_in_bytes: 
                nop 
first_pass_symbol_table_high_water_mark_in_words: 
                nop 
                end
 
A:\TATARA\EXAMPLES\NAMES>tatara /q longdef2.as longdef2.tro 
A:\TATARA\EXAMPLES\NAMES>tanren /m longuse longdef2 /o:l2.com 
... 
Symbols: 
  DR 0108 first_pass_symbol_table_high_water_mark_in_words 
  DR 0107 first_pass_symbol_table_high_water_mark_in_bytes 
2 modules, 15 records, ends at EOF. 
Wrote L2.COM, 0100-0108 (9 bytes).
 

どちらの名前も、それぞれのアドレスで照合されます。そのため、プログラムは、print_stringやkeyboard_buffer_lengthのように、ルーチンや変数にその内容どおりの名前を、すべてのモジュールを通じて付けられます。限度は255文字と、1行の長さだけです(7.2節)。

31.6 マクロの名前と/C

/Cは、シンボルだけでなくマクロの名前にも効きます(16.8節)。MACCASE.ASはTwiceという名前のマクロを定義し、2通りの大文字・小文字で1回ずつ使います。

; MACCASE.AS - a macro defined as Twice and used as twice. 
Twice           macro 
                nop 
                nop 
                endm 
                cseg 
                Twice 
                twice 
                end
 

/Cなしでは、どちらの行もマクロで、それぞれ2つのnopになります。

A:\TATARA\EXAMPLES\NAMES>tatara /p /s maccase.as 
... 
                cseg 
                Twice 
                nop 
                nop 
                twice 
                nop 
                nop 
                end 
... 
CSEG - default code segment, 0004h bytes
 

/C付きでは、twiceはマクロの名前でも、命令や疑似命令の名前でもありません。

A:\TATARA\EXAMPLES\NAMES>tatara /p /c /s maccase.as 
... 
MACCASE.AS(8): ERROR: not a directive, a macro or an instruction.
 

/Cを前提に書くソースでは、インクルード・ファイルのマクロ、たとえばsystemも含め、どのマクロも定義とまったく同じ大文字・小文字で使う必要があります。