DELPHI自带的原代码
function IntToHex(Value: Integer; Digits: Integer): string;
// FmtStr(Result, '%.*x', [Digits, Value]);
asm
CMP EDX, 32 // Digits < buffer length?
JBE @A1
XOR EDX, EDX
@A1: PUSH ESI
MOV ESI, ESP
SUB ESP, 32
PUSH ECX // result ptr
MOV ECX, 16 // base 16 EDX = Digits = field width
CALL CvtInt
MOV EDX, ESI
POP EAX // result ptr
CALL System.@LStrFromPCharLen
ADD ESP, 32
POP ESI
end;
function IntToHex(Value: Int64; Digits: Integer): string;
// FmtStr(Result, '%.*x', [Digits, Value]);
asm
CMP EAX, 32 // Digits < buffer length?
JLE @A1
XOR EAX, EAX
@A1: PUSH ESI
MOV ESI, ESP
SUB ESP, 32 // 32 chars
MOV ECX, 16 // base 10
PUSH EDX // result ptr
MOV EDX, EAX // zero filled field width: 0 for no leading zeros
LEA EAX, Value;
CALL CvtInt64
MOV EDX, ESI
POP EAX // result ptr
CALL System.@LStrFromPCharLen
ADD ESP, 32
POP ESI
end;