flat assembler
Message board for the users of flat assembler.
Index
> IDE Development > Updates to StrLib 
Author 

JohnFound
Hi decard.
I will include this in Fresh next release. decard wrote: I've just added two functions to strlib: StrCharPos that searches the string for a specified char Yesterday I thinked that I need such function. (BTW: Also other string+char functions > AddChar for example) Quote: and StrToNum that implements a simple string to number conversion. I've got one question about it: how do you think it should behave on error (maybe set carry flag?). Yea, we need this too. IMHO, it should use FASM's formats of numbers and be able to convert not only decimals. Quote: actually I wrote those functions because I am thinking of... some simple regular expression parser It is very good idea. But it is hard work too. I wish you luck. It will be very useful as part of Fresh standard library. Regards. 

03 Dec 2003, 15:58 

pelaillo
Hi decard,
is a good idea for your search and replace utility. I have find a brief implementation of RegEx in C++ well explained by Amer Gerzic. I think is a good starting point, I hope you find it useful 

03 Dec 2003, 16:06 

decard
Yea, I know it will be difficult... but I already found some info on the topic on the web, and it doesn't seem to be impossible


03 Dec 2003, 16:08 

decard
Hi pelaillo,
Thank you for this  I looken at it and I think it will be very helpful. 

04 Dec 2003, 13:43 

decard
Added StrCharCat and StrInsertChar.
Now I want to improve StrToNum, and I've got a question: should the string for conversion be ended with NULL? Or maybe to make this routine just stop processing when some nondigit char appears, without generating error? It would make possible to convert eg. something like this: numstr db "12345blahblah",0 ("blahblah" will be just ignored) [edit]outdated attachment removed[/edit] Last edited by decard on 18 May 2004, 20:21; edited 2 times in total 

13 Dec 2003, 18:18 

pelaillo
Test this. I have profiled against same functions by KetilO and R.Filatreault and I have saved some clocks:
Code: ;  ; AsciiToFp st0 < esi ; written by pelaillo ; December 30 2002 ; ; Based on AsciiToFp by Tim Roberts ; Improvements: ; Zero when empty string ; Discard after second decimal point ;  str_tofp: push ebx esi edi xor eax,eax mov [.sign],eax mov [.expsign],eax mov [.decimal],eax movzx eax,byte [esi] cmp al,'' je .minus_sign cmp al,'+' je .plus_sign jmp .sign_ok .minus_sign: inc [.sign] .plus_sign: inc esi movzx eax,byte [esi] .sign_ok: xor ebx,ebx fldz xor ecx,ecx .mantissa_loop: cmp eax,'E' je .exponent cmp eax,'e' je .exponent cmp eax,'.' je .dec_point xor eax,'0' cmp eax,9 ja .digits_ok mov [.temp],eax fmul [.ten] fiadd word [.temp] inc ebx jmp .no_point .dec_point: cmp [.decimal],0 jne .digits_ok mov [.decimal],ebx .no_point: inc esi movzx eax,byte [esi] jmp .mantissa_loop .exponent: inc esi movzx eax,byte [esi] cmp al,'' je .minus_exponent_sign cmp al,'+' je .plus_exponent_sign jmp .exponent_loop .minus_exponent_sign: inc [.expsign] .plus_exponent_sign: inc esi movzx eax,byte [esi] .exponent_loop: xor eax,'0' cmp eax,9 ja .digits_ok lea ecx,[ecx*4+ecx] lea ecx,[ecx*2+eax] inc esi movzx eax,byte [esi] jmp .exponent_loop .digits_ok: cmp [.expsign],0 je .exponent_ready neg ecx .exponent_ready: mov eax,[.decimal] or eax,eax je .no_decimals sub ebx,eax sub ecx,ebx .no_decimals: or ecx,ecx je .no_exponent mov eax,ecx ; call fexp10 .fexp10: ; mov ecx,eax cmp eax,0 jge .fexp_sign_ok neg eax .fexp_sign_ok: fld1 mov dl,al and edx,0Fh je .bigger_exp lea edx,dword [edx+edx*4] fld tword [edx*2+.ten_110] fmulp st1,st .bigger_exp: mov dl,al shr dl,4 and edx,0Fh je .still_bigger lea edx,dword [edx+edx*4] fld tword [edx*2+.ten_1610] fmulp st1,st .still_bigger: mov dl,ah and edx,1Fh je .exponent_sign lea edx,dword [edx+edx*4] fld tword [edx*2+.ten_25610] fmulp st1,st .exponent_sign: cmp ecx,0 jge .positive_exponent fdivp st1,st jmp .no_exponent .positive_exponent: fmulp st1,st .no_exponent: cmp [.sign],0 je .ready fchs .ready: pop edi esi ebx mov edi,esi call fp_tohex ret align 4 .sign dd 0 .expsign dd 0 .decimal dd 0 .temp dd 0 .ten dq 10.0 .ten_1 dt 1.0e1 dt 1.0e2 dt 1.0e3 dt 1.0e4 dt 1.0e5 dt 1.0e6 dt 1.0e7 dt 1.0e8 dt 1.0e9 dt 1.0e10 dt 1.0e11 dt 1.0e12 dt 1.0e13 dt 1.0e14 dt 1.0e15 .ten_16 dt 1.0e16 dt 1.0e32 dt 1.0e48 dt 1.0e64 dt 1.0e80 dt 1.0e96 dt 1.0e112 dt 1.0e128 dt 1.0e144 dt 1.0e160 dt 1.0e176 dt 1.0e192 dt 1.0e208 dt 1.0e224 dt 1.0e240 .ten_256 dt 1.0e256 dt 1.0e512 dt 1.0e768 dt 1.0e1024 dt 1.0e1280 dt 1.0e1536 dt 1.0e1792 dt 1.0e2048 dt 1.0e2304 dt 1.0e2560 dt 1.0e2816 dt 1.0e3072 dt 1.0e3328 dt 1.0e3584 dt 1.0e4096 dt 1.0e4352 dt 1.0e4608 dt 1.0e4864 

15 Dec 2003, 11:34 

decard
pelaillo: I can't compile it, fp_tohex is undefined.
I realized that I removed global definition from strlib.asm, I fixed it and uploaded in above post. 

15 Dec 2003, 16:49 

pelaillo
Sorry decard, I forget to post it. I find this in a year ago source.
Code: ; Float point to hex: ; edi < st0 fp_tohex: push esi edi mov esi,.fpnum fstp tword [esi] mov ecx,9 .conv_loop: mov al,[esi+ecx] shr al,4 call .HexOut mov al,[esi+ecx] and al,0Fh call .HexOut dec ecx jns .conv_loop mov byte [edi],0 pop edi esi ret .HexOut: cmp al,9 jbe .is_num add al,'A'10 jmp .ok_num .is_num: add al,'0' .ok_num: stosb ret .fpnum dt 0.0 

15 Dec 2003, 18:04 

decard
hi pelaillo,
I still can't make it work . Maybe I'm doing something wrong? I have no experience with coprocessor programming, so it could be my fault. Your routine takes a pointer to the string in esi, and returns a pointer to converted number in edi, right? Now I want to display the number using msvcrt printf. Your routine returns value in tword, while printf requires qword, so I'm converting it using FPU stack. Code: mov esi,szFp call str_tofp fld tword[edi] fstp [fp] invoke printf, szFmt,dword[fp+4],dword[fp] (...) szFp db "10.0",0 szFmt db "%f", 0 fp dq ? And it prints "0.000000". What am I doing wrong? Hmmm, maybe I should spend more time learing about FPU... 

21 Dec 2003, 11:59 

pelaillo
Hi decard, I will take a look.
A hint: If you are using OllyDbg, you can see the fpu registers content and look where it is failing. 

22 Dec 2003, 04:38 

< Last Thread  Next Thread > 
Forum Rules:

Copyright © 19992020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.