I think I found a bug in the implementation of ALTD DJNZ instruction. According to Rabbit instructions manual, the ASLD DJNZ should act on alternate register B' and decrement it. The observed behavior is that B' is set to 0xFF and not decremented.
The following program illustrates this issue:
Code:
// function returns 5
int take_5 ()
{
#asm
ld hl, 0
ld b, 5
.loop:
inc hl
djnz .loop
#endasm
}
// this is the buggy version
int alt_take_5 ()
{
#asm
ld hl, 0
altd ld b, 5
.loop:
inc hl
altd djnz .loop
#endasm
}
void main ()
{
int val;
brdInit();
val = take_5 ();
printf ("take 5 = %d\n", val);
val = alt_take_5 ();
printf ("alt take 5 = %d\n", val);
exit (0);
}
The bug shows on Rabbit 2000, 3000 and 4000 processors. I haven't tried on newer ones.