Message board for the users of flat assembler.
> Compiler Internals > label autodetection
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:
parse_line: 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 no_data_label: 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 ...
|12 Apr 2012, 21:29||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.