[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] It is more than: .byte SYMA - SYMB
From: |
Erik Christiansen |
Subject: |
[avr-gcc-list] It is more than: .byte SYMA - SYMB |
Date: |
Thu, 11 Sep 2003 12:23:06 +1000 |
User-agent: |
Mutt/1.3.28i |
On Tue, May 27, 2003 at 11:19:48AM +0200, Joerg Wunsch wrote:
> I tried to define a byte in avr-as to the difference of two
> (relocatable) symbols. I pulled my hair out, but failed so far.
>
> So something like:
>
> .text
> SYMA: mov rthis, rthat
> SYMB: ldi rthat, 42
> ...
> .byte SYMA-SYMB
The problem appears to be more widespread. While implementing a simple
assembly language struct:
.section .bss,"a"
.org 0x800060 <- To show the absolute case also fails.
q_length = 32
log_queue: .space q_length ; Queue of log data to be transmitted.
log_wr_ptr: .space 1 ; Write pointer
log_rd_ptr: .space 1 ; Read pointer
log_bytes: .space 1 ; Count of bytes queued.
.section .text,"ax",@progbits
ldd r16,Y+(log_bytes - log_queue) ; Byte count
ldd r17,Y+(log_rd_ptr - log_queue) ; Read pointer
cpse r16,zero ; Queue empty?
rjmp 1f
we are hit with: "Error: constant value required" on both the ldd lines.
As Jörg already explained, these expressions are an assembly-time
constant, fully resolvable, in the absolute case, without resort to even
the linker. And, as Jörg found with .word:
lbytes = (log_bytes - log_queue) ; Assembles without complaint.
but then:
ldd r16,Y+(lbytes) ; Shows it's still confused:
Error: constant value required
We can see in avr_get_constant (str, max) in
binutils-030512/gas/config/tc-avr.c, the failure to handle the constant
expression:
expression (&ex);
if (ex.X_op != O_constant)
as_bad (_("constant value required"));
Tracking the "#define expression(result) expr (0, result)" to
"segT expr (rankarg, resultP)", 242 lines of laborious hand parsing are
found. The really good news is that we have left tc-avr.c and are now in
the gas-generic expr.c file.
Maybe, instead of "expression (&ex);", the following (from
config/tc-avr.h) should be used. (Jörg mentions that .word works):
/* You may define this macro to parse an expression used in a data
allocation pseudo-op such as `.word'. You can use this to
recognize relocation directives that may appear in such directives. */
#define TC_PARSE_CONS_EXPRESSION(EXPR,N) avr_parse_cons_expression (EXPR,N)
void avr_parse_cons_expression (expressionS *exp, int nbytes);
Without getting seriously into it at this stage, it's clear that it uses
"expression()", so ex.X_op should be set. (With a bit of luck :-)
If the implementation had been lex/yacc, I'd just have made a quick
grammar tweak, but wading into somone else's hand beaten parser is
several orders of magnitude more murky. If a maintainer could offer some
pointers on whether I'm headed in the right direction, I'll still give
it a try.
In the interim, any suggested workaround would be welcome indeed!
Regards,
Erik
- [avr-gcc-list] It is more than: .byte SYMA - SYMB,
Erik Christiansen <=