Gee!
Thanks alot Rob.
The problem was where you said: in the SwapCardinal ASM function.
> ESI is typically used to manage the loop-control variable, too.
I think that was the reason it crushed after the first loop.
My ASM knowledge is somwhere behind me in Z80 ages.
I must update my ASM language.
I thought it was a compiler bug.
I had lots of those with Delphi 5. They where close related with arrays and my
procedure used an
external array. So I only checked the array stuff.
Plus, SwapCardinal function allways returned ok.
I have also tested that function in a small program but WITHOUT a 'for' loop.
And of course it worked! :)
I never thought to check again that function.
THANKS AGAIN!
--- Rob Kennedy <[EMAIL PROTECTED]> wrote:
> Human wrote:
> > The AV apear AFTER calling first time RReadUInt4 in FOR loop.
> >
> > function RReadUInt4(my_fp: TFilePtr): Cardinal;
> > { SWAP READ }
> > begin
> > { Seek (F, ?)}
> > BlockRead(my_fp^, Result, 4);
> > SwapCardinal(Result);
> > end;
>
> Change your code to this:
>
> function ReadUInt4(var F: File): Cardinal;
> begin
> BlockRead(F, Result, 4);
> SwapCardinal(Result);
> end;
>
> That is, pass the file variable by reference, not as a pointer.
>
> > Procedure SwapCardinal(Var LongVar: Cardinal); {Swap32bits unsigned
> > integer}
> > Asm
> > mov esi,longvar
>
> Ouch! Never modify ESI without first saving its old value. The only
> registers you're allowed to modify are EAX, ECX, and EDX. Others you need
> to save so that you can restore them afterward. This is probably the
> reason your code crashes. ESI is typically used to manage the loop-control
> variable, too.
>
> > xor eax,eax
> > mov ax,[esi]
> > xor edx,edx
> > mov dx,[esi+2]
> > mov [esi],dh
> > mov [esi+1],dl
> > mov [esi+2],ah
> > mov [esi+3],al
> > End;
>
> This entire function can be made much simpler:
>
> procedure SwapCardinal(var X: Cardinal);
> asm
> mov ecx, [eax]
> bswap ecx
> mov [eax], ecx
> end;
>
> The BSWAP instruction reverses the order of the bytes in a register. It's
> safe to overwrite ECX without saving its previous value. The parameter
> gets passed in EAX.
>
> --
> Rob
>
>
> __________________________________________________
> Delphi-Talk mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi-talk
>
...and the traveler died, stroked by the beauty of the landscape.
THE MORNING OF THE MAGICIANS
Louis Pawels & Jacques Bergier
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk