bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [m32r-elf] Error: bad instruction when using shigh and low macroswit


From: Nick Clifton
Subject: Re: [m32r-elf] Error: bad instruction when using shigh and low macroswith absolute immediate.
Date: Fri, 04 Jul 2003 18:30:57 +0100
User-agent: Gnus/5.1001 (Gnus v5.10.1) Emacs/21.2 (gnu/linux)

Hi Kazu,

> binutils-2.13.1 Released.

The latest release is 2.14, so it would probably be a good idea for
you to use these sources.  In this particular case however the
problems you are encountering will not be solved by upgrading.


> .equ SYM0,0xFFFF8000
> ; (Bug case 1) shigh() 0xFFFF0000 will be added 0x10000 => 0x100000000
>  seth r0,#shigh(SYM0) ; (Bug case 1)

I do not think that this is really a bug.  The shigh() macro takes a
value and returns the higher 16-bits.  If the 15th bit of the original
value is set then an carry is assumed to be added into the 16th bit.
Thus shigh (0xFFFF8000) is computed as:

    (0xFFFF8000 >> 16) + (0xFFFF8000 & 0x00008000 ? 1 : 0)

or:
     0x10000

Since this value cannot be held in 16 bits, the shigh() macro cannot
resolve its operand and so the instruction is invalid.

Note - the shigh() macro does *NOT* take into account how its argument
is used or whether the accompanying instruction using the low() macro
will actually set the carry bit.  It is up to the assembly language
programmer (or C compiler) to select the correct macros to use.  Thus
this pair of instructions:

  seth r0,#shigh(SYM0)
  or3 r0,r0,#low(SYM0)

should be correctly written as:

  seth r0,#high(SYM0)
  or3 r0,r0,#low(SYM0)
  

> ; (Bug case 2) shigh(),low() 0x8000 will be  used signed 16bit => 0xFFFF8000
>  add3 r0,r0,#low(SYM0) ; (Bug case 2)

This is because the assembler's default behaviour is to complain about
signed overflow in any field.  This can easily be changed however by
adding the -J switch to the assembler command line.  ie:

  m32r-elf-as -J -o test.o test.s

Cheers
        Nick
        





reply via email to

[Prev in Thread] Current Thread [Next in Thread]