#548 Z80 continuous shift operations

closed-fixed
Erik Petrich
z80 port (190)
5
2003-07-18
2003-07-17
Hidenori Hida
No

1.Sample code

#include <stdio.h>
#include <string.h>

int shift(int,int);

int main ()
{
return shift(0x1234,2);
}

int shift(int i,int n)
{
return (i>>(n*2))&0xf;
}

2.Command

sdcc -mz80 sample.c

3.Version

SDCC :
mcs51/gbz80/z80/avr/ds390/pic14/pic16/TININative/xa51
/ds400 2.3.5 (Jun 22 2003) (UNIX)

4.Error

It seems that continuous shift operations use same BC
register.
In following case, "109 ld a,c" , c register must be "n*2"
but c register is modified at "107 ld c,4(ix)", so c register
is "i".

98 ;sample2.c:13: return (i>>
(n*2))&0xf;
99 ; genLeftShift
100 ; AOP_STK for
0020 DD 4E 06 101 ld c,6(ix)
0023 DD 46 07 102 ld b,7(ix)
0026 CB 21 103 sla c
0028 CB 10 104 rl b
105 ; genRightShift
106 ; AOP_STK for
002A DD 4E 04 107 ld c,4(ix)
002D DD 46 05 108 ld b,5(ix)
0030 79 109 ld a,c
<====????????????
0031 3C 110 inc a
0032 C3r39s00 111 jp 00106$
0035 112 00105$:
0035 CB 28 113 sra b
0037 CB 19 114 rr c
0039 115 00106$:
0039 3D 116 dec a
003A C2r35s00 117 jp nz,00105$

5. Mail address

hida@mxic.co.jp

Discussion

  • Erik Petrich
    Erik Petrich
    2003-07-18

    Logged In: YES
    user_id=635249

    Fixed in src/z80/gen.c 1.110

     
  • Erik Petrich
    Erik Petrich
    2003-07-18

    • assigned_to: nobody --> epetrich
    • status: open --> closed-fixed