Numeric variables
+
+Within macros and other control structures ( , ...) it is sometimes useful to have some sort of
+variable. This can be achieved by the .SET operator. It creates a
+symbol that may get assigned a different value later:
+
+
+ four .set 4
+ lda #four ; Loads 4 into A
+ four .set 3
+ lda #four ; Loads 3 into A
+
+
+Since the value of the symbol can change later, it must be possible to
+evaluate it when used (no delayed evaluation as with normal symbols). So the
+expression used as the value must be constant.
+
+Following is an example for a macro that generates a different label each time
+it is used. It uses the function
+and a numeric variable named lcount .
+
+
+ .lcount .set 0 ; Initialize the counter
+
+ .macro genlab
+ .ident (.sprintf ("L%04X", lcount)):
+ lcount .set lcount + 1
+ .endmacro
@@ -731,14 +764,14 @@ You may use cheap local labels as an easy way to reuse common label
names like "Loop". Here is an example:
- Clear: lda #$00 ; Global label
- ldy #$20
- @Loop: sta Mem,y ; Local label
- dey
- bne @Loop ; Ok
- rts
+ Clear: lda #$00 ; Global label
+ ldy #$20
+ @Loop: sta Mem,y ; Local label
+ dey
+ bne @Loop ; Ok
+ rts
Sub: ... ; New global label
- bne @Loop ; ERROR: Unknown identifier!
+ bne @Loop ; ERROR: Unknown identifier!
Unnamed labels
@@ -754,23 +787,23 @@ reference (use the n'th label in forward direction). An example will help to
understand this:
- : lda (ptr1),y ; #1
- cmp (ptr2),y
- bne :+ ; -> #2
- tax
- beq :+++ ; -> #4
- iny
- bne :- ; -> #1
- inc ptr1+1
- inc ptr2+1
- bne :- ; -> #1
+ : lda (ptr1),y ; #1
+ cmp (ptr2),y
+ bne :+ ; -> #2
+ tax
+ beq :+++ ; -> #4
+ iny
+ bne :- ; -> #1
+ inc ptr1+1
+ inc ptr2+1
+ bne :- ; -> #1
- : bcs :+ ; #2 -> #3
- ldx #$FF
- rts
+ : bcs :+ ; #2 -> #3
+ ldx #$FF
+ rts
- : ldx #$01 ; #3
- : rts ; #4
+ : ldx #$01 ; #3
+ : rts ; #4
As you can see from the example, unnamed labels will make even short
@@ -792,15 +825,15 @@ possible with the other symbol types).
Example:
- .DEFINE two 2
- .DEFINE version "SOS V2.3"
+ .DEFINE two 2
+ .DEFINE version "SOS V2.3"
- four = two * two ; Ok
- .byte version ; Ok
+ four = two * two ; Ok
+ .byte version ; Ok
- .PROC ; Start local scope
- two = 3 ; Will give "2 = 3" - invalid!
- .ENDPROC
+ .PROC ; Start local scope
+ two = 3 ; Will give "2 = 3" - invalid!
+ .ENDPROC
@@ -3079,7 +3112,7 @@ Here's a list of all control commands and a description, what they do:
.MACPACK
-
+
Insert a predefined macro package. The command is followed by an
identifier specifying the macro package to insert. Available macro
packages are: