StrToInt的问题(100分)

  • 主题发起人 主题发起人 中国最猥琐的程序员
  • 开始时间 开始时间

中国最猥琐的程序员

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