-

「Z80 Assembler Reference Manual」の版間の差分

提供: HI-TECH C for CP/M Fan WIKI(JP)
移動先: 案内検索
(タグ: モバイル編集モバイルウェブ編集)
(使用法)
(タグ: モバイル編集モバイルウェブ編集)
4行目: 4行目:
 
Z180プロセッサ用に追加されたオプコードも許容します。
 
Z180プロセッサ用に追加されたオプコードも許容します。
  
== Usage ==
+
==使用法==
  
The assembler is named zas, and is invoked as follows:
+
アセンブラはZASという名前で、次のように指定されます。
  
  ZAS options files ...
+
  ZAS options files...
  
 
+
このファイルは一つ、もしくはそれ以上のアセンブル対象となるアセンブラソースファイルですが、注意すべきなのは、すべてのファイルが一つのファイルとしてアセンブルされることです。個別のファイルにはなりません。
The files are one or more assembler source files  which
+
個別のファイルにアセンブルするには、アセンブラがそれぞれのファイルに個別に指定されなければいけません。オプションは0個もしくはそれ以上んも次のオプションからなります。
will be assembled, but note that all the files are assembled
 
as one, not as separate files.  To assemble separate  files,
 
the  assembler  must be invoked on each file separately. The
 
options are zero or more options from the following list:
 
  
 
;-N
 
;-N
:Ignore arithmetic  overflow  in  expressions.  The  -N option suppresses the normal check for arithmetic overflow. The assembler follows the "Z80 Assembly  Language Handbook"  in its treatment of overflow, and in certain instances this can lead to an error where in  fact  the expression  does  evaluate  to  what the user intended. This option may be used to override the overflow checking.
+
:expressionの算術的なオーバーフローを無視します。-Nオプションは算術的オーバーフローを抑制します。アセンブラはオーバーフローの扱いにおいて「Z80アセンブリ言語ハンドブック」に従います。またある種のインスタンスにおいて、これはユーザーが意図していたものを実際に評価し、エラーとなります。このオプションはオーバーフローチェックのオプションを上書きするために使われます。
  
 
;-J
 
;-J
:Attempt to optimize jumps to branches.  The  -J  option will request the assembler to attempt to assemble jumps and conditional jumps as relative branches where possible.  Only  those  conditional  jumps  with  branch equivalents will be optimized, and jumps will  only  be optimized  to  branches  where  the target is in branch range. Note that the  use  of  this  option  slows  the assembly  down,  due to the necessity for the assembler to make an additional pass over the input code.
+
:分岐ジャンプを最適化しようとします。-Jオプションはアセンブラに対してジャンプと条件ジャンプを、可能な部分であれば相対分岐としてアセンブルするようにリクエストします。分岐の等価物を持つこれらの条件ジャンプのみが最適化されます。ジャンプはターゲットが分岐の範囲内にある分岐のみが最適化されます。これはアセンブラに対して入力されたコードをパスに追加する必要があるため?このオプションの使用はアセンブルの速度を低下させます。
  
 
;-U
 
;-U
:Treat undefined symbols as  external.  The  -U  option will suppress error messages relating to undefined symbols. Such symbols are  treated  as  externals  in  any case.  The use of this option will not alter the object code generated, but merely serves to suppress the error messages.
+
:未定義のシンボルを外部関数として扱います。-Uオプションは未定義のシンボルに関するエラーメッセージを抑制します。このようなシンボルはどんな場合であっても、外部関数として扱われます。このオプションの使用は生成されたオブジェクトを変更しませんが、エラーメッセージの抑制をおこしません??
  
 +
;-Ofile
 +
:オブジェクトコードをファイル内に配置します。デフォルトオブジェクトファイル名は最初のソースファイル名から構築されます。ファイル名の中の拡張子やファイルの型(つまり、"."よりも右側)が切り取られ、拡張子.objが追加されます。そのため、以下のコマンド
  
;-O<strong>file</strong>
+
  ZAS file.as file2.z80
:Place the object code in <strong>file</strong>.  The default object file name  is constructed from the name of the first source file. Any suffix or file type (i.e. anything  following the  rightmost  dot  ('.') in the name is stripped, and the suffix .obj appended. Thus the command
 
  
ZAS file1.as file2.z80
+
:はfile1.objというオブジェクトファイルを生成します。-Oオプションの使用はこのデフォルトの便利さを上書きし、オブジェクトファイルに任意の名前をつけることを許容します。たとえば
 
 
:will produce an object file called file1.obj.  The  use of the -O option will override this default convention, allowing the object file to be arbitrarily  named.  For example:
 
  
 
  ZAS -ox.obj file1.obj
 
  ZAS -ox.obj file1.obj
  
:will place the object code in x.obj.
+
x.objのオブジェクトコードの中にオブジェクトコードが配置されます。
  
 
;-L<strong>list</strong>
 
;-L<strong>list</strong>
:Place an assembly listing in the file <strong>list</strong>, or on standard  output if <strong>list</strong> is null A listfile may be produced with the -L option. If a file name is supplied  to  the option,  the  list file will be created with that name, otherwise the listing will be written to standard  output  (i.e.  the  console). List file names such as CON: and LST: are acceptable.
+
アセンブラのリスティングをlistファイルに置くか、listがnullの場合はリストファイルが-Lオプションで作成されます。
 +
:もし、ファイル名がこのオプションに与えられると、その名前でリストファイルが作成され、それ以外の場合、リスティングは標準出力(つまりコンソールへ)書き出されます。
 +
 +
<nowiki>CON:</nowiki><nowiki>LST:</nowiki>といったファイル名が使えます。
  
 
;-W<strong>width</strong>
 
;-W<strong>width</strong>
:The listing is to be formatted for a printer  of  given <strong>width</strong> The  -W  option specifies the width to which the listing is to be formatted. E.g.
+
このリスティングはプリンタを与えられた<strong>width</strong>の幅でフォーマットします。
 +
-Wオプションはリスティングがどれくらいの幅にするか、指定するオプションです。
  
 
  ZAS -Llst: -W80 x.as
 
  ZAS -Llst: -W80 x.as
  
:will output  a  listing  formatted  for  an  80  column printer to the list device.
+
:これはlistデバイス80カラム用にリスティングを整形してアウトプットします。
  
 
;-C
 
;-C
:This options requests ZAS to  produce  cross  reference information  in a file. The file will be called <strong>xxx</strong>.crf where <strong>xxx</strong> is the base part of  the  first  source  file name. It will then be necessary to run the CREF utility to turn this information into a formatted listing.
+
:このオプションはZASに対し、クロスリファレンス情報を書くリクエストをします。
 +
 
 +
:このファイルは<strong>xxx</strong>.crfと呼ばれ、
 +
<strong>xxx</strong> は最初のソースファイル名の基本部分です。
 +
:これはCREFユーティリティを走らせる時に必要で、この情報が整形されたリスティングに変わります。
  
 
== The Assembly Language ==
 
== The Assembly Language ==

2017年8月17日 (木) 06:44時点における版

HI-TECH Cコンパイラシステムに同梱のアセンブラは機能完全版の、ザイログニーモニックを解するリロケータブルマクロアセンブラです。このニーモニック及び、Z80アセンブラ言語はザイログ社発行の「Z80アセンブリ言語ハンドブック」で記述されており、このマニュアルにもリファレンスとして含まれています。 アセンブラはオペランドに特定のexpressionを許容し、またここで記述される疑似命令も同様です。 アセンブラはHitachi64180や Z180プロセッサ用に追加されたオプコードも許容します。

使用法

アセンブラはZASという名前で、次のように指定されます。

ZAS options files...

このファイルは一つ、もしくはそれ以上のアセンブル対象となるアセンブラソースファイルですが、注意すべきなのは、すべてのファイルが一つのファイルとしてアセンブルされることです。個別のファイルにはなりません。 個別のファイルにアセンブルするには、アセンブラがそれぞれのファイルに個別に指定されなければいけません。オプションは0個もしくはそれ以上んも次のオプションからなります。

-N
expressionの算術的なオーバーフローを無視します。-Nオプションは算術的オーバーフローを抑制します。アセンブラはオーバーフローの扱いにおいて「Z80アセンブリ言語ハンドブック」に従います。またある種のインスタンスにおいて、これはユーザーが意図していたものを実際に評価し、エラーとなります。このオプションはオーバーフローチェックのオプションを上書きするために使われます。
-J
分岐ジャンプを最適化しようとします。-Jオプションはアセンブラに対してジャンプと条件ジャンプを、可能な部分であれば相対分岐としてアセンブルするようにリクエストします。分岐の等価物を持つこれらの条件ジャンプのみが最適化されます。ジャンプはターゲットが分岐の範囲内にある分岐のみが最適化されます。これはアセンブラに対して入力されたコードをパスに追加する必要があるため?このオプションの使用はアセンブルの速度を低下させます。
-U
未定義のシンボルを外部関数として扱います。-Uオプションは未定義のシンボルに関するエラーメッセージを抑制します。このようなシンボルはどんな場合であっても、外部関数として扱われます。このオプションの使用は生成されたオブジェクトを変更しませんが、エラーメッセージの抑制をおこしません??
-Ofile
オブジェクトコードをファイル内に配置します。デフォルトオブジェクトファイル名は最初のソースファイル名から構築されます。ファイル名の中の拡張子やファイルの型(つまり、"."よりも右側)が切り取られ、拡張子.objが追加されます。そのため、以下のコマンド
ZAS file.as file2.z80
はfile1.objというオブジェクトファイルを生成します。-Oオプションの使用はこのデフォルトの便利さを上書きし、オブジェクトファイルに任意の名前をつけることを許容します。たとえば
ZAS -ox.obj file1.obj

x.objのオブジェクトコードの中にオブジェクトコードが配置されます。

-Llist

アセンブラのリスティングをlistファイルに置くか、listがnullの場合はリストファイルが-Lオプションで作成されます。

もし、ファイル名がこのオプションに与えられると、その名前でリストファイルが作成され、それ以外の場合、リスティングは標準出力(つまりコンソールへ)書き出されます。

CON:やLST:といったファイル名が使えます。

-Wwidth

このリスティングはプリンタを与えられたwidthの幅でフォーマットします。

¥-Wオプションはリスティングがどれくらいの幅にするか、指定するオプションです。
ZAS -Llst: -W80 x.as
これはlistデバイス80カラム用にリスティングを整形してアウトプットします。
-C
このオプションはZASに対し、クロスリファレンス情報を書くリクエストをします。
このファイルはxxx.crfと呼ばれ、

xxx は最初のソースファイル名の基本部分です。

これはCREFユーティリティを走らせる時に必要で、この情報が整形されたリスティングに変わります。

The Assembly Language

As mentioned above, the assembly language accepted by zas is based on the Zilog mnemonics. You should have some reference book such as the "Z80 Assembly Language Handbook". Described below are those areas in which zas differs, or has extensions, compared to the standard Zilog assembly language.

Symbols

The symbols (labels) accepted by the assembler may be of any length, and all characters are significant. The characters used to form a symbol may be chosen from the upper and lower case alphabetics, the digits 0-9, and the special symbols underscore ('_'), dollar ('$') and question mark ('?'). The first character may not be numeric. Upper and lower case are distinct. The following are all legal and distinct symbols.

An_identifier
an_identifier
an_identifier1
$$$
?$_123455

Note that the symbol $ is special (representing the current location) and may not be used as a label. Nor may any opcode or pseudo-op mnemonic, register name or condition code name. You should note the additional condition code names described later.

Temporary Labels

The assembler implements a system of temporary labels, useful for use within a localized section of code. These help eliminate the need to generate names for labels which are referenced only in the immediate vicinity of their definition, for example where a loop is implemented.

A temporary label takes the form of a digit string. A reference to such a label requires the same digit string, plus an appended b or f to signify a backward or forward reference respectively. Here is an example of the use of such labels.

entry_point:   ;This is referenced from far away
    ld   b,10
1:  dec  c
    jr   nz,2f ;if zero, branch forward to 2:
    ld   c,8
    djnz 1b    ;decrement and branch back to 1:
    jr   1f    ;this does not branch to the
               ;same label as the djnz
2:  call fred  ;get here from the jr nz,2f
1:  ret        ;get here from the jr 1f


The digit string may be any positive decimal number 0 to 65535. A temporary label value may be re-used any number of times. Where a reference to e.g. 1b is made, this will reference the closest label 1: found by looking backwards from the current point in the file. Similarly 23f will reference the first label 23: found by looking forwards from the current point in the file.

Constants

Constants may be entered in one of the radices 2, 8, 10 or 16. The default is 10. Constants in the other radices may be denoted by a trailing character drawn from the following set:

Character Radix Name
B 2 binary
O 8 octal
Q 8 octal
o 8 octal
q 8 octal
H 16 hexadecimal
h 16 hexadecimal

Hexadecimal constants may also be specified in C style, for example LD A,0x21. Note that a lower case b may not be used to indicate a binary number, since 1b is a backward reference to a temporary label 1:.

Character Constants

A character constant is a single character enclosed in single quotes ('). Multi character constants may be used only as an operand to a DEFM pseudo-op.

Floating Constants

A floating constant in the usual notation (e.g. 1.234 or 1234e-3) may be used as the operand to a DEFF pseudo-op.

Opcode Constants

Any z80 opcode may be used as a constant in an expres- sion. The value of the opcode in this context will be the byte that the opcode would have assembled to if used in the normal way. If the opcode is a 2-byte opcode (CB or ED prefix byte) only the second byte of the opcode will be used. This is particularly useful when setting up jump vectors. For example:

ld   a,jp         ;a jump instruction
ld   (0),a        ;0 is jump to warm boot
ld   hl,boot      ;done here
ld   (1),hl


Expressions

Expressions are constructed largely as described in the "Z80 Assembly Language Handbook".

Operators

The following operators may be used in expressions:

Operator Meaning
& Bitwise AND
* Multiplication
+ Addition
- Subtraction
.and. Bitwise AND
.eq. Equality test
.gt. Signed greater than
.high. Hi byte of operand
.low. Low byte of operand
.lt. Signed less than
.mod. Modulus
.not. Bitwise complement
.or. Bitwise or
.shl. Shift left
.shr. Shift right
.ult. Unsigned less than
.ugt. Unsigned greater than
.xor. Exclusive or
/ Divison
< Signed less than
= Equality
> Signed greater than
^ Bitwise or


Operators starting with a dot "." should be delimited by spaces, thus label .and. 1 is valid but label.and.1 is not.

Relocatability

Zas produces object code which is relocatable; this means that it is not necessary to specify assembly time where the code is to be located in memory. It is possible to do so, by use of the ORG pseudo-op, however the preferred approach is to use program sections or psects. A psect is a named section of the program, in which code or data may be defined at assembly time. All parts of a psect will be loaded contiguously into memory, even if they were defined in separate files, or in the same file but separated by code for another psect. For example, the following code will load some executable instructions into the psect named text, and some data bytes into the data psect.


    psect text, global

alabel:
    ld    hl,astring
    call  putit
    ld    hl,anotherstring

    psect data, global
astring:
    defm  'A string of chars'
    defb  0
    anotherstring:
    defm  'Another string'
    defb  0

    psect text

putit:
    ld    a,(hl)
    or    a
    ret   z
    call  outchar
    inc   hl
    jr    putit


Note that even though the two blocks of code in the text psect are separated by a block in the data psect, the two text psect blocks will be contiguous when loaded by the linker. The instruction "ld hl,anotherstring" will fall through to the label "putit:" during execution. The actual location in memory of the two psects will be determined by the linker. See the linker manual for information on how psect addresses are determined.

A label defined in a psect is said to be relocatable, that is, its actual memory address is not determined at assembly time. Note that this does not apply if the label is in the default (unnamed) psect, or in a psect declared abso- lute (see the PSECT pseudo-op description below). Any labels declared in an absolute psect will be absolute, that is their address will be determined by the assembler.

With the version of ZAS supplied with version 7 or later of HI-TECH C, relocatable expressions may be combined freely in expressions. Older versions of ZAS allowed only limited arithmetic on relocatable expressions.

擬似命令

擬似命令は、"Z80アセンブリ言語ハンドブック"の記述に依拠し、いくつかの追加があります。

DEFB, DB

この擬似命令はエクスプレッションのコンマ区切りリストの後に置かれます。

一続きのバイトロケーションにアセンブルされます。

どのエクスプレッションも-128から255の値を内包する必要があります。 DBはDBFBのシノニムとして使うことができます。

例:

DEFB  10, 20, 'a', 0FFH
DB    'hello world',13,10,0

DEFF

この擬似命令は浮動小数点数コンスタントを32bitのHI-TECH Cフォーマットの浮動小数点数コンスタントにアセンブルします。

pi: DEFF  3.14159

DEFW

エクスプレッションを値に制限のないワードにアセンブルすること以外はDEFBと似ています。

例:

DEFW  -1, 3664H, 'A', 3777Q


DEFS

DEFSは初期化することなしにメモリロケーションをリザーブします。
このオペランドは絶対的なエクスプレッションで、リザーブされるされるバイト数を表現します。
このエクスプレッションは現在のロケーションカウンターに追加されます。
しかしながら、DEFSによってリザーブされたロケーションがプログラムの中間の場合、リンカによってゼロに初期化される可能性があります。

例:

DEFS  20h   ;メモリの32バイトをリザーブ

EQU

EquはEQUの左に、シンボルの値を

右にエクスプレッションを設定します。

既にていぎされているシンボルの値を設定するのは違反です。
例:
 SIZE      equ   46

DEFL

既に存在するシンボルを再定義できることを除いて、EQUと同じです。

例:

 SIZE      defl  48

DEFM

DEFMはシングルクォートで囲まれた、文字列の後に続かなければいけません。
これら文字のASCII コードは連続したメモリにアセンブルされます。

例:

DEFM  'A string of funny *@$ characters'

END

ソースファイルの終わり、もしくは擬似命令ENDがアセンブルの終了を意味します。
擬似命令ENDはオプション的に、プログラムの開始アドレスを定義するエクスプレッションに続いて現れることがあります。
これはCP/Mでは本当のところ、便利ではありません。ただ1つの開始アドレスだけがプログラムごとに定義されます。それ以上ある場合はリンカが文句をいいます。

例:

END   somelabel

COND, IF, ELSE, ENDC

条件的アセンブルはCOND擬似命令によって、提供されます。
CONDのオペランドは絶対的なエクスプレッションでなければいけません。
もし、この値が偽(ゼロ)の場合、CONDから続き、対応するENDC擬似命令の部分まではアセンブルされません。
COND/ENDCのペアはネストが可能です。
IFがCONDのシノニムとして使用可能です。
ELSE擬似命令をCOND/ENDCブロックの中に含むことができます。

例:

IF    CPM
call  5
ELSE
call  os_func
ENDC

ELSE

COND参照

ENDC

COND参照

ENDM

MACRO参照

PSECT

この擬似命令は再配置可能なプログラムセクションの定義を許可します。
この引数はオプション的にpsectフラッグの後に着く、psect nameです。
psect名はラベルと同じルールに従って構築されるシンボルですが、psectは、衝突することなくラベルと同じ名前を持つことができます。
psect名はPSECT擬似命令の後で、のみ認識されます。psectフラグは以下の通りです。
ABS
Psectは絶対値です。
GLOBAL
Psectはグローバルです。
LOCAL
Psectはグローバルではありません。
OVRLD
Psectはリンカによってオーバーラップ可能です
PURE
Psectはリードオンリーでなければいけません
Psectがもしグローバルな場合、リンカはこれを、他モジュールで同名の他のグローバルpsectとマージします。
ローカルのpsectは他のモジュールからの、他のpsectとは区別されます。Psectはデフォルトでグローバルです。
デフォルトでリンカはいろいろなモジュールからのpsect内で、コードを連結します。
psectがOVRLDとして指定されると、リンカがそれぞれのモジュールを、そのpsectにオーバーラップしていきます。
初期化する時や、ベクター割り込みする時など、モジュールをリンクをする特定の場合に便利です。
PUREフラグは、psectが実行時にのみリードオンリーになり得るとリンカに伝えます。
このフラグの有用性はリンカが要求を強制する能力に依存します。CP/Mは悲しいことに、ここに配慮されていません?
ABSフラグはpsectを絶対化します。
psectはゼロに読み込まれます。
これは静的にベクター割り込みを初期化し、テーブルにジャンプする時に有用です。

例:

PSECT     text, global, pure
PSECT     data, global
PSECT     vectors, ovrld

GLOBAL

GLOBAL はもう1つのシンボルに続いて(カンマ区切りで)使われなければいけません。これはinternalでもexternalでも、現在のモジュールの内部で依存していてもいなくても、アセンブラにグローバルとして取り扱われます。
例:
GLOBAL      label1, putchar, _printf

ORG

擬似命令ORGは現在のpsectをデフォルト(絶対)psectに設定し、絶対表現としなければならないロケーションカウンタをオペランドとします。

例:

ORG   100H

MACRO

この擬似命令はマクロを定義します。マクロ名に前置する要素も後続する要素もあります。

カンマ区切りのフォーマルパラメータがオプション的に後続します。

MACRO擬似命令に後続し、次のENDMまでのコードの行がマクロ本体として格納されます。
マクロ名は後続するアセンブラステートメントのオプコード部分でも使われ、実際のパラメータが後続します。
マクロの本体は、その部分で、対応する実際のパラメータを持つフォーマルパラメータと置き換えられます??
例:
print     MACRO string
    psect data
999:      db    string,'$'
    psect text
    ld    de,999b
    ld    c,9
    call  5
    ENDM
使用されると、このマクロはマクロの本体で、実際のパラメータの代用である関数と引数の3つのインストラクションに展開されます??
従って、print hello world' は次のように展開されます。
    psect data
999:      db    'hello world','$'
    psect text
    ld    de,999b
    ld    c,9
    call  5
マクロの引数はかぎ括弧('<' と '>')で閉じてコンマなどのデリミタキャラクタを含む任意のテキストを渡すために使うことが可能です。
例えば、キャリッジリターンとラインフィードを含む文字列を先ほど定義したprintマクロで使いたいとしましょう。

その場合のマクロを以下のように発動させたとします。

print 'hello world',13,10
しかしこれは失敗します。なぜなら13と10が追加の引数として扱われて、無視されるからです。コンマを含む文字列を単体の引数として渡すためには、次のように書きます。
print <'hello world',13,10>
これで 'hello world',13,10というテキストを単体の引数として渡すことができるでしょう。これは次のようなコードに展開されます。
    psect data
999:      db    'hello world',13,10,'$'
    psect text
    ld    de,999b
    ld    c,9
    call  5
ZASは古いバージョンのZASや他のZ80アセンブラとの互換性のため、2種類のマクロ定義をサポートしています。

マクロ名はMACRO擬似命令の前のラベルフィールドでも、MACRO擬似命令の後のオペランドフィールドでも定義できます。

そのため、この2つのマクロ定義は等価です。
bdos      MACRO func,arg
ld    de,arg
ld    c,func
call  5
ENDM
MACRO bdos,func,arg
ld    de,arg
ld    c,func
call  5
ENDM

LOCAL

LOCAL擬似命令はマクロの拡張のため、ユニークなラベルを定義できます。
LOCALディレクティブの後にシンボルがリスト化されている場合、マクロが展開される時に、これらは代わりの

ユニークなアセンブラ生成シンボルとなります。

copy      MACRO source,dest,count
    LOCAL nocopy
    push  af
    push  bc
    ld    bc,source
    ld    a,b
    or    c
    jr    z,nocopy
    push  de
    push  hl
    ld    de,dest
    ld    hl,source
    ldir
    pop   hl
    pop   de
nocopy:   pop   bc
    pop   af
    ENDM
nocopyの位置に展開されたコードがユニークなアセンブラ生成ラベルを含む場合には、例えば、copy(recptr),buf,(recsize)は次のように展開されます。
    push  af
    push  bc
    ld    bc,(recsize)
    ld    a,b
    or    c
    jr    z,??0001
    push  de
    push  hl
    ld    de,buf
    ld    hl,(recptr)
    ldir
    pop   hl
    pop   de
??0001:   pop   bc
    pop   af
2回目に発動する際には、nocopyラベルは??0002に展開されます。

REPT

REPT擬似命令は引数によってていぎされただけ、複数回展開されるテンポラリマクロを定義します。

例:

REPT  3
ld    (hl),0
inc   hl
ENDM

これは次のように展開されます。

ld    (hl),0
inc   hl
ld    (hl),0
inc   hl
ld    (hl),0
inc   hl

IRP と IRPC

IRPとIRPCディレクティブはREPTに似ていますが、ブロックを決まった回数繰り返すのではなく、引数リスト化にある回数それぞれを一回だけ実行します。

IRPの場合はリストはコンベンショナルマクロの引数リスト、IRPCの場合は文字列からの連続する文字です。

例:

    IRP   string,<'hello world',13,10>,'arg2'
    LOCAL str
    psect data
str:      db    string,'$'
    psect text
    ld    c,9
    ld    de,str
    call  5
    ENDM

これは次のように展開されます。

    psect data
??0001:   db    'hello world',13,10,'$'
    psect text
    ld    c,9
    ld    de,??0001
    call  5
    psect data
??0002:   db    'arg2','$'
    psect text
    ld    c,9
    ld    de,??0002
    call  5


コンベンショナルマクロを使用する際と同様に、LOCALラベルとかぎ括弧の使用に注意してください。

IRPCを最もよく表す例は以下のものです。

IRPC  char,ABC
ld    c,2
ld    e,'char'
call  5
ENDM

これは次のように展開されます。

ld    c,2
ld    e,'A'
call  5
ld    c,2
ld    e,'B'
call  5
ld    c,2
ld    e,'C'
call  5

追加条件コード

このアセンブラはいくつかの追加条件コードを認識します。 これらは次の通りです。

Codeコード Equivalent等価物 Meaning意味
alt m 数学的な"小なり"Arithmetic less than
llt c 論理的な"小なり"Logical less than
age p 数学的な"大なりイコール"Arithmetic greater or equal
lge nc 論理的な"大なりイコール"Logical greater or equal
di ld a,iの後に使う
ei 割り込み可能フラグの
評価です。それぞれ、
可能、不可能。

アセンブラディレクティブ

アセンブラディレクティブはソースファイルにおける行で、これはコードを生成せず、むしろアセンブラの振る舞いを変えます。

どのディレクティブも行の初めのカラムにアスタリスクがつくのでわかります。 これは単語のすぐあとにつき、最初の文字のみを見ます。

ディレクティブ自体を含む行はリスト化されません。ディレクティブは以下の通りです

*Title
このディレクティブ後続する行をリスティングのタイトルとして使います。
*Heading
このディレクティブに続く行をリスティングのサブタイトルとして使います。*Ejectにも影響します。
*List
ONやOFFを後に伴い、リストをそれぞれオンオフします。このディレクティブはマクロの内部や、そのマクロやインクルードファイルをコントロールするインクルードファイルでも使われる可能性があります。
以前のリスティング状態はマクロやインクルードファイルから戻った時に回復されます。
*Include
ディレクティブに後続するファイル名が、この時点でアセンブラにインクルードされます。
*Eject
新しいページをこの時点で開始します。ソースのフォームフィールド文字も同じ効果を持ちます。
これらのディレクティブのいくつかの例を挙げます。
*Title Widget Control Program
*Heading Initialization Phase
*Include widget.i

診断

アセンブル中に遭遇したそれぞれのエラーに対してエラーメッセージが標準エラーストリームに書き出されます。 このメッセージはファイル名と行番号を特定し、エラーを記述します。

エラーの起きた行のリスティングに加えて、エラーを示す1文字のフラグが立ちます。

文字と対応するメッセージは次の通りです。


A
Absolute expression required絶対表現が必要です。
B
Bad arg to *Lの引数が不正です
Bad arg to IMの引数が不正です
Bad bit numberビット番号が不正です
Bad character constant文字定数が不正です
Bad jump conditionジャンプ条件が不正です
D
Directive not recognized認識されないディレクティブです
Digit out of range数字が範囲外です
E
EOF inside conditionalEOFが条件の中にあります
Expression error

エクスプレッションエラーです

G
Garbage after operandsオペランドの後にガーベジがあります
Garbage on end of line行末にガーベジがあります
I
Index offset too largeインデックオフセットが大きすぎます
J
Jump target out of rangeジャンプターゲットが範囲外です
L
Lexical errorレキシカルエラーです
M
Multiply defined symbolシンボルを複数回定義しました
O
Operand errorオペランドエラーです
P
Phase errorフェーズエラーです
Psect may not be local and global

psectはローカルとグローバルにできません

R
Relocation errorリロケーションエラーです
S
Size errorサイズエラーです
Syntax error構文エラーです
U
Undefined symbol未定義のシンボルです
Undefined temporary label未定義のテンポラリラベルをです
Unterminated string閉じていない文字列です

Z80/Z180/64180 インストラクションセット

この章の残りの部分はZ80、Z180、64180、NSC800の完全なインストラクションセットのために割かれています。Z180と64180 は全てのZ80の命令が実行できますが、タイミングが異なります。