[hatari-devel] Strange behaviour with ROL.B ?

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi everybody,


I encounter a situation I can't explain for now with ROL.B and the Carry flag in the 68030 state register.


My example program :

Clear d7

Set d0 to 9

rol.b d0 2 times with values $10 and $40 and check the C flag of the  state register after each rol.

rol.b d0 by $10   (if carry bit is set, add 1 to d7)

rol.b d0 by $40   (if carry bit is set, add 2 to d7)

Then I display the value of d7 on screen (0, 1, 2 or 3) depending of the state of the Carry bit.


When I run the program, I can read on screen  "3"; which means that the carry bit was "1" for the 2 rol instructions.

When I trace the program under hatari debugger (which is supposed to be non intrusive for the CPU), I can see that the second rol set the carry bit to 0.

The result of D7 is 1 instead of 3.

When I run my "current project ;)", I have the feeling that sometimes the carry bit is 0 and sometimes 1 but I can't find a general rule for this.

Any idea ?

Regards

Laurent


The example program :

            clr.l        d7

            moveq        #9,d0

            moveq        #$10,d1
            moveq        #$40,d2


            rol.b        d1,d0
            bcc.s        .test2
            addq.w        #1,d7

..test2:            rol.b        d2,d0
            bcc.s        .display_result
            addq.w        #2,d7
..display_result:
            add.w        #$32,d7


         ; Display the value of D7
            move.w        d7,-(sp)     ; Offset 2
            move.w        #2,-(sp)     ; Offset 0
            trap        #1           ; GEMDOS
            addq.l        #4,sp        ; Correct stack


toto:            bra.s        toto


When I run it under hatari, I can read "3"


When I trace it (in another run), I can see :

Before the first rol.b by #$10

CPU=$2e1dc, VBL=1082, FrameCycles=198808, HBL=194, LineCycles=152, DSP=$51
$0002e1dc : e338                               rol.b d1,d0
> r
  D0 00000009   D1 00000010   D2 00000040   D3 00000000
  D4 00000000   D5 00000000   D6 00000000   D7 00000000
  A0 00000000   A1 00000000   A2 00000000   A3 00000000
  A4 0002E290   A5 0002E27E   A6 00DE0AC6   A7 00DE0AF8
USP  00DE0AF8 ISP  00008870 SFC  00000000 DFC  00000000
CACR 00003111 VBR  00000000 CAAR 00000000 MSP  00000000
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=0 IMASK=3 STP=0
0: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
2: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
4: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
6: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
FPSR: 00000000 FPCR: 00000000 FPIAR: 00000000 N=0 Z=0 I=0 NAN=0
Prefetch 0002e1e0 5247e538 (1) 6402 (1) 5247 (1) e538 (1)
0002E1DC e338                     ROL.B D1,D0
Next PC: 0002e1de
> c 1
Returning to emulation for 1 CPU instructions...


Just after the first rol.b , carry = 1

CPU=$2e1de, VBL=1082, FrameCycles=198808, HBL=194, LineCycles=152, DSP=$51
$0002e1de : 6402                               bcc.s $2e1e2
> r
  D0 00000009   D1 00000010   D2 00000040   D3 00000000
  D4 00000000   D5 00000000   D6 00000000   D7 00000000
  A0 00000000   A1 00000000   A2 00000000   A3 00000000
  A4 0002E290   A5 0002E27E   A6 00DE0AC6   A7 00DE0AF8
USP  00DE0AF8 ISP  00008870 SFC  00000000 DFC  00000000
CACR 00003111 VBR  00000000 CAAR 00000000 MSP  00000000
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=1 IMASK=3 STP=0
0: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
2: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
4: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
6: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
FPSR: 00000000 FPCR: 00000000 FPIAR: 00000000 N=0 Z=0 I=0 NAN=0
Prefetch 0002e1e0 5247e538 (2) 5247 (1) e538 (1) 5247 (1)
0002E1DE 6402                     BCC.B #$02 == $00000000 (F)
Next PC: 0002e1e0
> c 1
Returning to emulation for 1 CPU instructions...

CPU=$2e1e0, VBL=1082, FrameCycles=198816, HBL=194, LineCycles=160, DSP=$51
$0002e1e0 : 5247                               addq.w #1,d7
> r
  D0 00000009   D1 00000010   D2 00000040   D3 00000000
  D4 00000000   D5 00000000   D6 00000000   D7 00000000
  A0 00000000   A1 00000000   A2 00000000   A3 00000000
  A4 0002E290   A5 0002E27E   A6 00DE0AC6   A7 00DE0AF8
USP  00DE0AF8 ISP  00008870 SFC  00000000 DFC  00000000
CACR 00003111 VBR  00000000 CAAR 00000000 MSP  00000000
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=1 IMASK=3 STP=0
0: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
2: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
4: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
6: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
FPSR: 00000000 FPCR: 00000000 FPIAR: 00000000 N=0 Z=0 I=0 NAN=0
Prefetch 0002e1e4 64025447 (1) e538 (1) 6402 (1) 5447 (1)
0002E1E0 5247                     ADDQ.W #$01,D7
Next PC: 0002e1e2
> c 1
Returning to emulation for 1 CPU instructions...


Just before the second rol.b by #$40

CPU=$2e1e2, VBL=1082, FrameCycles=198816, HBL=194, LineCycles=160, DSP=$51
$0002e1e2 : e538                               rol.b d2,d0
> r
  D0 00000009   D1 00000010   D2 00000040   D3 00000000
  D4 00000000   D5 00000000   D6 00000000   D7 00000001
  A0 00000000   A1 00000000   A2 00000000   A3 00000000
  A4 0002E290   A5 0002E27E   A6 00DE0AC6   A7 00DE0AF8
USP  00DE0AF8 ISP  00008870 SFC  00000000 DFC  00000000
CACR 00003111 VBR  00000000 CAAR 00000000 MSP  00000000
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=0 IMASK=3 STP=0
0: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
2: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
4: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
6: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
FPSR: 00000000 FPCR: 00000000 FPIAR: 00000000 N=0 Z=0 I=0 NAN=0
Prefetch 0002e1e4 64025447 (2) 6402 (1) 5447 (1) 6402 (1)
0002E1E2 e538                     ROL.B D2,D0
Next PC: 0002e1e4
> c 1
Returning to emulation for 1 CPU instructions...


Just after the second rol, Carry bit is still 0

CPU=$2e1e4, VBL=1082, FrameCycles=198816, HBL=194, LineCycles=160, DSP=$51
$0002e1e4 : 6402                               bcc.s $2e1e8
> r
  D0 00000009   D1 00000010   D2 00000040   D3 00000000
  D4 00000000   D5 00000000   D6 00000000   D7 00000001
  A0 00000000   A1 00000000   A2 00000000   A3 00000000
  A4 0002E290   A5 0002E27E   A6 00DE0AC6   A7 00DE0AF8
USP  00DE0AF8 ISP  00008870 SFC  00000000 DFC  00000000
CACR 00003111 VBR  00000000 CAAR 00000000 MSP  00000000
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=0 IMASK=3 STP=0
0: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
2: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
4: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
6: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
FPSR: 00000000 FPCR: 00000000 FPIAR: 00000000 N=0 Z=0 I=0 NAN=0
Prefetch 0002e1e4 64025447 (2) 5447 (1) 6402 (1) 5447 (1)
0002E1E4 6402                     BCC.B #$02 == $00000000 (T)
Next PC: 0002e1e6
> c 1
Returning to emulation for 1 CPU instructions...


D7 = 1 instead of the awaited 3


CPU=$2e1e8, VBL=1082, FrameCycles=198832, HBL=194, LineCycles=176, DSP=$51
$0002e1e8 : de7c 0032                          add.w #$32,d7
> r
  D0 00000009   D1 00000010   D2 00000040   D3 00000000
  D4 00000000   D5 00000000   D6 00000000   D7 00000001
  A0 00000000   A1 00000000   A2 00000000   A3 00000000
  A4 0002E290   A5 0002E27E   A6 00DE0AC6   A7 00DE0AF8
USP  00DE0AF8 ISP  00008870 SFC  00000000 DFC  00000000
CACR 00003111 VBR  00000000 CAAR 00000000 MSP  00000000
T=00 S=0 M=0 X=0 N=0 Z=0 V=0 C=0 IMASK=3 STP=0
0: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
2: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
4: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
6: 7FFF-FFFFFFFF-FFFFFFFF +nan 7FFF-FFFFFFFF-FFFFFFFF +nan
FPSR: 00000000 FPCR: 00000000 FPIAR: 00000000 N=0 Z=0 I=0 NAN=0
Prefetch 0002e1ec 3f073f3c (1) 0032 (1) 3f07 (1) 3f3c (1)
0002E1E8 de7c 0032                ADD.W #$0032,D7
Next PC: 0002e1ec









Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/