Consider the following C code:
Code: Select all
char *p;
for ( p=Fileend; p>Curschar; p-- )
{
*p = *(p-1);
}
I rewrote the loop in assembler:
Code: Select all
psect text
global _Curschar
global _Fileend
;Init
ld bc,(_Fileend) ;p=Fileend
inc bc ;p=Fileend+1
loop1: dec bc ;p--
dec bc ;p--
ld a,(bc) ;get char to be moved (swap=*p)
inc bc ;copy it (p++)
ld (bc),a ;..to p (*p=swap)
ld h,b
ld l,c
ld de,(_Curschar) ;have we reached the insert point?
ld a,h
cp d
jp nz, loop1
ld a,l
cp e
jp nz,loop1
Cheers
JonB
PS, the assembler algorithm looks like this is C, and it works.
Code: Select all
char* p=Fileend;
char swap;
for(;;)
{
p--;
swap=*p;
p++;
*p=swap;
if(p-Curschar == 0) break;
p--;
}