Delphi里面两种版本都有啊,我帮你贴出汇编版本。<br>FUNCTION _ValLong( s: AnsiString; VAR code: Integer ) : Longint<br>asm<br>{ <br>{ ->EAX Pointer to string } //第一个参数用EAX传递<br>{ EDX Pointer to code result } //第二个参数用EDX传递,属于Register CALL调用惯例<br>{ <-EAX Result }<br><br> PUSH EBX<br> PUSH ESI<br> PUSH EDI<br><br> MOV ESI,EAX<br> PUSH EAX { save for the error case }<br><br> TEST EAX,EAX<br> JE @@empty<br><br> XOR EAX,EAX<br> XOR EBX,EBX<br> MOV EDI,07FFFFFFFH / 10 { limit }<br><br>@@blankLoop:<br> MOV BL,[ESI]<br> INC ESI<br> CMP BL,' '<br> JE @@blankLoop<br><br>@@endBlanks:<br> MOV CH,0<br> CMP BL,'-'<br> JE @@minus<br> CMP BL,'+'<br> JE @@plus<br><br>@@checkDollar:<br> CMP BL,'$'<br> JE @@dollar<br><br> CMP BL, 'x'<br> JE @@dollar<br> CMP BL, 'X'<br> JE @@dollar<br> CMP BL, '0'<br> JNE @@firstDigit<br> MOV BL, [ESI]<br> INC ESI<br> CMP BL, 'x'<br> JE @@dollar<br> CMP BL, 'X'<br> JE @@dollar<br> TEST BL, BL<br> JE @@endDigits<br> JMP @@digLoop<br><br>@@firstDigit:<br> TEST BL,BL<br> JE @@error<br><br>@@digLoop:<br> SUB BL,'0'<br> CMP BL,9<br> JA @@error<br> CMP EAX,EDI { value > limit ? }<br> JA @@overFlow<br> LEA EAX,[EAX+EAX*4]<br> ADD EAX,EAX<br> ADD EAX,EBX { fortunately, we can't have a carry }<br><br> MOV BL,[ESI]<br> INC ESI<br><br> TEST BL,BL<br> JNE @@digLoop<br><br>@@endDigits:<br> DEC CH<br> JE @@negate<br> TEST EAX,EAX<br> JGE @@successExit<br> JMP @@overFlow<br><br>@@empty:<br> INC ESI<br> JMP @@error<br><br>@@negate:<br> NEG EAX<br> JLE @@successExit<br> JS @@successExit { to handle 2**31 correctly, where the negate overflows }<br><br>@@error:<br>@@overFlow:<br> POP EBX<br> SUB ESI,EBX<br> JMP @@exit<br><br>@@minus:<br> INC CH<br>@@plus:<br> MOV BL,[ESI]<br> INC ESI<br> JMP @@checkDollar<br><br>@@dollar:<br> MOV EDI,0FFFFFFFH<br><br> MOV BL,[ESI]<br> INC ESI<br> TEST BL,BL<br> JZ @@empty<br><br>@@hDigLoop:<br> CMP BL,'a'<br> JB @@upper<br> SUB BL,'a' - 'A'<br>@@upper:<br> SUB BL,'0'<br> CMP BL,9<br> JBE @@digOk<br> SUB BL,'A' - '0'<br> CMP BL,5<br> JA @@error<br> ADD BL,10<br>@@digOk:<br> CMP EAX,EDI<br> JA @@overFlow<br> SHL EAX,4<br> ADD EAX,EBX<br><br> MOV BL,[ESI]<br> INC ESI<br><br> TEST BL,BL<br> JNE @@hDigLoop<br><br> DEC CH<br> JNE @@successExit<br> NEG EAX<br><br>@@successExit:<br> POP ECX { saved copy of string pointer }<br> XOR ESI,ESI { signal no error to caller }<br><br>@@exit:<br> MOV [EDX],ESI<br> POP EDI<br> POP ESI<br> POP EBX<br>end;