mikeakohn / naken_asm

Assembler for MSP430, dsPIC, ARM, MIPS, 65xx, 68000, 8051/8052, Atmel AVR8, and others.
http://www.mikekohn.net/micro/naken_asm.php
GNU General Public License v3.0
294 stars 50 forks source link

EQU crash and weirdness #118

Open erkkah opened 1 year ago

erkkah commented 1 year ago

I found some interesting things while porting old code containing EQU.

1

This example makes the assembler crash with a stack overflow:

    XA  EQU R1
    XA  EQU R1
    mov XA, #0

In the real world example, there is more code between the repeated equ - statements. I guess the second statement expands to R1 EQU R1 which causes the assembler to enter that spiral.

Not sure what the best solution is here. If it's expected behaviour to have macro expansions on the lvalue - side, then the recursion needs to be detected.

2

Replacing EQU with .define does not cause a crash, the duplicate definition is detected and logged, but the assembler reports success. Maybe an error that is not passed up?

3

If there is only a single space between XA and EQU in the example, another weird thing happens:

Error: Unknown instruction 'R1equ' at ...
erkkah commented 1 year ago

Oh, BTW, I'm happy to look into these with some guidance from you. I'm in the middle of other things and wanted to report this while I remember.

mikeakohn commented 1 year ago

Hmmm.. that should really be an error since XA was already defined?

I'd actually prefer to make changes / fixes to the core of the assembler myself... is this blocking you?

mikeakohn commented 1 year ago
.msp430
xa equ r2
xa equ r3
mov #0, &xa

This seems to bomb out with an error (not a duplicate though). It would have to do a look-ahead to figure out the next token is equ which would probably not be very efficient.

erkkah commented 1 year ago

Not blocking, but it would be neat to find some kind of workaround, being able to re-define or un-define would help. There is a bit of register setup in front of functions, and several functions use the same defines.

If there is no other way to solve it now, I can just use plain old documentation.

erkkah commented 1 year ago

One solution I came up with is to wrap each function in a macro which is directly expanded. Then I can use the macro parameters as local defines. :)