1

I'm trying to write a macro to create "headers" in a linked list fashion.

In each header the first 2 bytes should be the address of the previous header starting address (0000 in the first header).

I managed to create the header label (h_label) using .ident(). At this point I try to "save" the current header start address using:

        h_label .set .ident (.concat ("h_", label))

but I get this error Error: Constant expression expected.

I get the same error if I try using the '*' (PC) like this:

        h_label .set 0+*

Any idea what I am doing wrong? Any way I could achieve this?

My code for now looks like this:

latest  .set 0
h_label .set 0

.macro  defword   label, strname, immflag
; h_LABEL:
.ident (.concat ("h_", label)):
        h_label .set .ident (.concat ("h_", label))
        .ADDR latest
        .byte   ( .strlen(strname) + immflag*128)
        .byte   strname
        latest .set h_label
; do_LABEL:
.ident (.concat ("do_", label)):
.endmacro

.CODE
        defword "DUP", "DUP", 0
        LDA #$12  ; dummy code 
        LDA #$34  ; dummy code 

        defword "SWAP", "SWAP", 1
        LDA #$56  ; dummy code 
        LDA #$78  ; dummy code 

1 Answer 1

2

Like the name says, they are numeric variables. They can hold numbers and nothing else. This is confirmed by the documentation.

I would instead try something like this:

__word_last .set 0
__word_0 = 0

.macro defword strname
    .ident (.sprintf("__word_%u", __word_last + 1)):

    .addr .ident(.sprintf("__word_%u", __word_last))
    .byte (.strlen (strname))
    .byte strname

    __word_last .set __word_last + 1
.endmacro

.org $1000

defword "foo"
lda #$12
lda #$34

defword "quux"
lda #$56
lda #$78

defword "xyzzy"
lda #$9a
lda #$bc

The above generates this in my listing file:

001000  1  00 00 03 66  defword "foo"
001004  1  6F 6F        
001006  1  A9 12        lda #$12
001008  1  A9 34        lda #$34
00100A  1               
00100A  1  00 10 04 71  defword "quux"
00100E  1  75 75 78     
001011  1  A9 56        lda #$56
001013  1  A9 78        lda #$78
001015  1               
001015  1  0A 10 05 78  defword "xyzzy"
001019  1  79 7A 7A 79  
00101D  1  A9 9A        lda #$9a
00101F  1  A9 BC        lda #$bc
00101F  1               
1
  • Thanks for your suggestion, I'll try that, looks like it's what I need indeed. Thanks Jun 20, 2021 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .