flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > label autodetection

Thread Post new topic Reply to topic

Joined: 02 Apr 2010
Posts: 517
Location: Munich
As maybe you know, I created a Z80 version of FASM.
I am now creating a version of flat assembler for Sinclairs old ZX81 computer, which support Z80 assembler and ZX81 BASIC. So for that I have to implement several features.

One feature now realized is an an auto label detection method. Labels have to be created with either directive label or ":" at the end of the label. I found several listings where the last ":" character is missing. On the other hand I need numeric labels as well as line numbers for BASIC program. Okay this is optional (can be autonumbered) but for compatibility it should be used on request like this.

I now implemented this feature in PARSER.INC in following manner:

      mov     [formatter_symbols_allowed],0
       cmp     byte [esi],1Ah
      jne     empty_instruction
   push    edi
 add     esi,2
       movzx   ecx,byte [esi-1]

        <read first item on line>

 cmp     byte [esi+ecx],':'
    je      simple_label
        cmp     byte [esi+ecx],'='
        je      constant_label
      call    get_instruction
     jnc     main_instruction_identified
 cmp     byte [esi+ecx],1Ah
  jne     no_data_label
       push    esi ecx
     lea     esi,[esi+ecx+2]
     movzx   ecx,byte [esi-1]
    call    get_data_directive
  jnc     data_label
  pop     ecx esi
 call    get_data_directive
  jnc     main_instruction_identified
 pop     edi

       <code similiar to simple_label and checked it item is first item on line>
       <if not first item following code is executed, otherwise simple_label>

        sub     esi,2
       xor     bx,bx
       call    parse_line_contents
 jmp     parse_next_line

So I interpret the first item of a line as label when it is
* not a preprocessor instruction (which is handled by PREPROCE.INC)
* not a simple label
* not a constant label
* not an instruction
* not a data label

Is this the best way to do ?
Anyway it is working in all contexts with Z80.
Is it checked again "reserved words" ?
Maybe a simple hack how to do this (I think it is not).

This feature have to be switched on anyway with a comment in source.

Only first item is checked, so have to be at the beginning of the line.
Can be fixed to start of line (no whitespace) with

Maybe if Tomasz has time and is in the mood to check and answer or somebody else ...
Post 12 Apr 2012, 21:29
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.