mainZ80 assembler - Support: sr #108869, suggestion: DEFL or SET for...

 
 

sr #108869: suggestion: DEFL or SET for variables

Submitter:  Marcos Cruz <programandala>
Submitted:  Sun 16 Aug 2015 05:21:29 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  1 - Wish Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 28 Jun 2018 04:32:12 PM UTC, comment #2: 

Hello Bas,

Thank you for your detailed answer. No matter the delay :)

In 2015 tried also binutils, but finally I chose Pasmo (http://pasmo.speccy.org), which supports this feature with the `defl` directive.

Of course, variables are available only if already set. I've fed Pasmo with your example code, and it issues an error on the second line, as expected ("`bar` is undefined"):



foo: defl 1
ld a, foo + bar
foo: defl foo + 1
ld b, foo + bar
bar: defl 2



Variable labels are ordinary labels, except they can get a new value any time. In order to prevent errors, you must give them a default or initial value at the start. Anyway, using a different directive, say `defl`, is important: `equ` constants are what you want most of the times.

Variables are especially useful with macros. In my project (http://programandala.net/en.program.solo_forth.html) I use
them to keep track of memory address pointers during the assembly. You can see examples by searching the Z80 source (https://github.com/programandala-net/solo-forth/blob/master/src/kernel.z80s) for "defl".

Thank you

Marcos Cruz <programandala>
Sat 16 Jun 2018 07:28:43 AM UTC, comment #1: 

Sorry for being a few years late.

If this is still relevent, please let me know if I understand you correctly; I'm not familiar with the concept of variables in an assembler:

The idea would be to have a variable that can change value during the assembling process? So similar to equ, but with the ability to redefine the constant to a new value?

I think this is an interesting concept, but it needs some thought for how it should be implemented. In z80asm, expressions are attempted to be computed as soon as possible, but if that is not possible yet, due to undefined labels, it tries again later. That complicates the idea of variables. For example, suppose that equ would not produce errors for duplicate definitions, but instead redefine the value, this should work fine:

foo: equ 1
ld a, foo
foo: equ foo + 1
ld b, foo

and it results in "ld a,1; ld b,2".

However, when this would be done:

foo: equ 1
ld a, foo + bar
foo: equ foo + 1
ld b, foo + bar
bar: equ 2

Now evaluating the expressions will fail until bar is defined. At that point, foo is 2, so it would produce "ld a,4; ld b,4", which is not what you'd want.

So for this to be implemented properly, every unresolved expression must contain a copy of all variables at the time of its definition, so that they can be used when all its references are defined.

It sounds like an interesting idea, but it's not easy. I don't think I have time to work on it any time soon, but patches are welcome. :)

(Note that "duplicate definition" errors are useful, so it shouldn't be implemented like in my examples above; variables should be different from constants, so a new command will be needed.)

Bas Wijnen <shevek>
Group administrator
Sun 16 Aug 2015 05:21:29 PM UTC, original submission:  

I'm trying z80asm as an alternative for my current Z80 assembler.

In order to adapt the Z80 sources of a complex project I need three features not all Z80 assemblers provide: creation of labels in macros, based on macro parameters; change the program counter; and variables.

z80asm provides a powerful `macro` with text substitution, and a `seek` directive, but unfortunately no support for variables. Other assemblers provide `defl` or `set`.

Marcos Cruz <programandala>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by shevek (Posted a comment)
  • -email is unavailable- added by programandala (Submitted the item)
  • -email is unavailable- added by programandala
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-08-16 programandala Carbon-Copy- Added programandala

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code