Fri 20 Jan 2006 09:03:42 PM UTC, original submission:
If we compile the following code with:
m6811-elf-gcc -m68hc12 -S -Os b-2006-01-20.c -da -mshort
the generate code is wrong. The following insn:
xgdx
stab 2,x
xgdx
which corresponds to the RTL:
(insn:HI 19 17 21 0 0xb7fd72ec (set (mem/s/v:QI (plus:HI (reg/v/f:HI 2 y [54])
(const_int 3 [0x3])) [0 <variable>.dirB+0 S1 A8])
(reg:QI 2 y [54])) 30 {*movqi_68hc12} (nil)
(nil))
is emitted. It is wrong because of the xgdx.
Gcc emits this because reg 54 is 0 and the code wants
to clear the memory at 2,x.
typedef struct
{
volatile unsigned char portA;
volatile unsigned char portB;
volatile unsigned char dirA;
volatile unsigned char dirB;
} MEBI_Regs;
void ReadExternalBus( unsigned int addr )
{
MEBI_Regs mebi = (MEBI_Regs)0;
// Write the address to the port A and B registers
mebi->portB = addr;
mebi->portA = addr>>8;
// Change ports A and B to inputs
mebi->dirA = 0;
mebi->dirB = 0;
}
int main( void )
{
ReadExternalBus( 0x1000 );
}
|