x86机器代码,65字节
00000000: 31c0 4180 3930 7cfa 8079 0161 7ef4 8079 1.A.90|..y.a~..y
00000010: ff31 7418 31db 8a19 83eb 308a 9300 0000 .1t.1.....0.....
00000020: 0031 db43 3851 010f 44c3 eb0a 31db 4380 .1.C8Q..D...1.C.
00000030: 7901 740f 44c3 c374 736e 7274 7474 7474 y.t.D..tsnrttttt
00000040: 74 t
部件:
section .text
global func
func: ;the function uses fastcall conventions
;ecx=first arg to function (ptr to input string)
xor eax, eax ;reset eax to 0
read_str:
inc ecx ;increment ptr to string
cmp byte [ecx], '0'
jl read_str ;if the char isn't a digit, get next digit
cmp byte [ecx+1], 'a'
jle read_str ;if the char after the digit isn't a letter, get next digit
cmp byte [ecx-1], '1'
je tens ;10-19 have different rules, so jump to 'tens'
xor ebx, ebx ;reset ebx to 0
mov bl, byte [ecx] ;get current digit and store in bl (low byte of ebx)
sub ebx, 0x30 ;convert ascii digit to number
mov dl, [lookup_table+ebx] ;get correct ordinal from lookup table
xor ebx, ebx ;reset ebx to 0
inc ebx ;set ebx to 1
cmp byte [ecx+1], dl ;is the ordinal correct according to the lookup table?
cmove eax, ebx ;if the ordinal is valid, set eax (return reg) to 1 (in ebx)
jmp end ;jump to the end of the function and return
tens:
xor ebx, ebx ;reset ebx to 0
inc ebx ;set ebx to 1
cmp byte [ecx+1], 't' ;does it end in th?
cmove eax, ebx ;if the ordinal is valid, set eax (return reg) to 1 (in ebx)
end:
ret ;return the value in eax
section .data
lookup_table db 'tsnrtttttt'
在线尝试!