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