mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Correct rgbasm(5) about whitespace before labels
Also rephrase some more label-related documentation
This commit is contained in:
@@ -839,7 +839,7 @@ A block of
|
|||||||
.Nm
|
.Nm
|
||||||
code that can be invoked later.
|
code that can be invoked later.
|
||||||
.It Sy String equate
|
.It Sy String equate
|
||||||
String symbol that can be evaluated, similarly to a macro.
|
A text string that can be expanded later, similarly to a macro.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
Symbol names can contain letters, numbers, underscores
|
Symbol names can contain letters, numbers, underscores
|
||||||
@@ -848,15 +848,19 @@ hashes
|
|||||||
.Sq #
|
.Sq #
|
||||||
and at signs
|
and at signs
|
||||||
.Sq @ .
|
.Sq @ .
|
||||||
However, they must begin with either a letter, or an underscore.
|
However, they must begin with either a letter or an underscore.
|
||||||
Periods
|
Periods
|
||||||
.Sq \&.
|
.Sq \&.
|
||||||
are allowed exclusively for labels, as described below.
|
are allowed exclusively in labels, as described below.
|
||||||
A symbol cannot have the same name as a reserved keyword.
|
A symbol cannot have the same name as a reserved keyword.
|
||||||
.Em \&In the line where a symbol is defined there must not be any whitespace before it ,
|
.Pp
|
||||||
|
Constants and string equates
|
||||||
|
.Em must not
|
||||||
|
have any whitespace before their name when they are defined;
|
||||||
otherwise
|
otherwise
|
||||||
.Nm
|
.Nm
|
||||||
will treat it as a macro invocation.
|
will treat them as a macro invocation.
|
||||||
|
Label and macro definitions may have whitespace before them, since a leading period or a following colon distinguishes them from invoking a macro.
|
||||||
.Bl -tag -width indent
|
.Bl -tag -width indent
|
||||||
.It Sy Label declaration
|
.It Sy Label declaration
|
||||||
One of the assembler's main tasks is to keep track of addresses for you, so you can work with meaningful names instead of "magic" numbers.
|
One of the assembler's main tasks is to keep track of addresses for you, so you can work with meaningful names instead of "magic" numbers.
|
||||||
@@ -866,57 +870,65 @@ This can be done in a number of ways:
|
|||||||
GlobalLabel:
|
GlobalLabel:
|
||||||
AnotherGlobal:
|
AnotherGlobal:
|
||||||
\&.locallabel
|
\&.locallabel
|
||||||
\&.yet_a_local:
|
\&.another_local:
|
||||||
AnotherGlobal.with_another_local:
|
AnotherGlobal.with_another_local:
|
||||||
ThisWillBeExported:: ;\ Note the two colons
|
ThisWillBeExported:: ;\ Note the two colons
|
||||||
ThisWillBeExported.too::
|
ThisWillBeExported.too::
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Declaring a label (global or local) with
|
Any label whose name does not contain a period is a global label.
|
||||||
|
Declaring a global label sets it as the current scoped label, until the next global one.
|
||||||
|
Global labels must be followed by one or two colons.
|
||||||
|
.Pp
|
||||||
|
Any label whose name contains a single period is a local label.
|
||||||
|
Label names cannot contain more than one period.
|
||||||
|
If the period is the first character, it will have the current scoped label's name implicitly prepended.
|
||||||
|
Local labels may optionally be followed by one or two colons.
|
||||||
|
Local labels can be declared as
|
||||||
|
.Ql scoped.local
|
||||||
|
or simply as
|
||||||
|
.Ql .local .
|
||||||
|
If the former notation is used, then
|
||||||
|
.Ql scoped
|
||||||
|
must actually be the current scoped label.
|
||||||
|
.Pp
|
||||||
|
Declaring a label (global or local) with two colons
|
||||||
.Ql ::
|
.Ql ::
|
||||||
does an
|
will
|
||||||
.Ic EXPORT
|
.Ic EXPORT
|
||||||
at the same time.
|
and define it at the same time.
|
||||||
(See
|
(See
|
||||||
.Sx Exporting and importing symbols
|
.Sx Exporting and importing symbols
|
||||||
below).
|
below).
|
||||||
.Pp
|
.Pp
|
||||||
Any label whose name does not contain a period is a global label, others are locals.
|
|
||||||
Declaring a global label sets it as the current label scope until the next one; any local label whose first character is a period will have the global label's name implicitly prepended.
|
|
||||||
Local labels can be declared as
|
|
||||||
.Ql scope.local:
|
|
||||||
or simply as as
|
|
||||||
.Ql .local: .
|
|
||||||
If the former notation is used, then
|
|
||||||
.Ql scope
|
|
||||||
must be the actual current scope.
|
|
||||||
.Pp
|
|
||||||
Local labels may have whitespace before their declaration as the only exception to the rule.
|
|
||||||
.Pp
|
|
||||||
.Sy Anonymous labels
|
.Sy Anonymous labels
|
||||||
are useful for short blocks of code.
|
are useful for short blocks of code.
|
||||||
They are defined like normal labels, but without a name before the colon.
|
They are defined like normal labels, but without a name before the colon.
|
||||||
Defining one does not change the label scope (unlike global labels).
|
Anonymous labels are independent of label scoping, so defining one does not change the scoped label, and referencing one is not affected by the current scoped label.
|
||||||
Referencing one is done using a colon
|
.Pp
|
||||||
|
Anonymous labels are referenced using a colon
|
||||||
.Ql \&:
|
.Ql \&:
|
||||||
followed by pluses
|
followed by pluses
|
||||||
.Ql +
|
.Ql +
|
||||||
or minuses
|
or minuses
|
||||||
.Ql - .
|
.Ql - .
|
||||||
|
Thus
|
||||||
.Ic :+
|
.Ic :+
|
||||||
references the next one after the expression,
|
references the next one after the expression,
|
||||||
.Ic :++
|
.Ic :++
|
||||||
the one after it, and so on.
|
the one after that;
|
||||||
The logic is similar for -, just backwards.
|
.Ic :-
|
||||||
|
references the one before the expression;
|
||||||
|
and so on.
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
ld hl, :++
|
ld hl, :++
|
||||||
: ld a, [hli] ; Jumps to here
|
: ld a, [hli] ; referenced by "jr nz"
|
||||||
ldh [c], a
|
ldh [c], a
|
||||||
dec c
|
dec c
|
||||||
jr nz, :-
|
jr nz, :-
|
||||||
ret
|
ret
|
||||||
|
|
||||||
: ; This address referenced by "ld hl"
|
: ; referenced by "ld hl"
|
||||||
dw $7FFF, $1061, $03E0, $58A5
|
dw $7FFF, $1061, $03E0, $58A5
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
|
|||||||
Reference in New Issue
Block a user