The MASM Forum

General => The Workshop => Topic started by: TouEnMasm on October 12, 2014, 01:28:53 AM

Title: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: TouEnMasm on October 12, 2014, 01:28:53 AM
Why only unsigned number ?
There is just a very few lines to add for signed or unsigned Numbers.
Example:satodw

; #########################################################################

satodw proc String:DWORD
    local moins:DWORD
  ; ----------------------------------------
  ; Convert decimal string signed or unsigned into dword value
  ; return value in eax
  ; ----------------------------------------

    push esi
    push edi

    xor eax, eax
   mov moins,0
    mov esi, String
   .if byte ptr [esi] == "-" || byte ptr [esi] == "+"
        .if byte ptr [esi] == "-"
inc esi
                mov moins,1
         .else
                inc esi
         .endif
   .endif
    xor ecx, ecx
    xor edx, edx
    mov al, [esi]
    inc esi
    cmp al, 2D
    jne proceed
    mov al, byte ptr [esi]
    not edx
    inc esi
    jmp proceed

  @@:
    sub al, 30h
    lea ecx, dword ptr [ecx+4*ecx]
    lea ecx, dword ptr [eax+2*ecx]
    mov al, byte ptr [esi]
    inc esi

  proceed:
    or al, al
    jne @B
    lea eax, dword ptr [edx+ecx]
    xor eax, edx
   .if moins == 1
not eax
                inc eax
   .endif
    pop edi
    pop esi

    ret

satodw endp
Title: Re: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: hutch-- on October 12, 2014, 01:32:04 AM
> Why only unsigned number ?

Easy, that is what it was designed to do. I am not personally a fan of multiple combined capacities, just do one of each.
Title: Re: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: dedndave on October 12, 2014, 05:03:16 AM
in this case, signed makes sense, though   :P

if it's unsigned, there shouldn't be a "-" in front of it - lol
Title: Re: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: TouEnMasm on October 12, 2014, 05:06:31 AM
I have posted a modified atodw who accept the sign - and + and signed number.
Title: Re: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: jj2007 on October 12, 2014, 08:46:15 AM
Quote from: dedndave on October 12, 2014, 05:03:16 AM
if it's unsigned, there shouldn't be a "-" in front of it

Valid point :t
Title: Re: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: hutch-- on October 12, 2014, 11:25:10 AM
I have always encouraged people to write what they like but this library will retain the distinction between signed and unsigned, I don't support the idea of blending capacities together, its the slippery slope to un-analysed high level objects instead of being components.
Title: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: TouEnMasm on October 13, 2014, 12:17:28 AM
To make please everyone,i have recall it satodw,(signed atodw)
OK ?
Title: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: hutch-- on October 13, 2014, 12:46:44 AM
Try the module "atol proc lpSrc:DWORD", it handles signed DWORD values.
Title: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: TouEnMasm on October 13, 2014, 03:28:00 AM
same results and same speed than the satodw.
bad thing,the name made a conflict with the crt function.
The crt function atol add a control of the overflow,-80000000h to 7FFFFFFFh (msdn)

Title: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: hutch-- on October 13, 2014, 10:41:57 AM
 :biggrin:

It does not conflict with crt_atoi which is the form that masm32 calls the MSVCRT dll. The point being that you never ever change an existing functionality of a procedure or you break someone's code. As far as the name, priority is given to procedures in the library over any external procedure names.
Title: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: jj2007 on October 13, 2014, 11:41:44 AM
BTW what happened to atou (http://masm32.com/board/index.php?topic=1357.msg13795#msg13795)?
Title: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: TouEnMasm on October 13, 2014, 05:42:31 PM
 :biggrin:
Quote
It does not conflict with crt_atoi
Do not be in conflict with itself is a great success  :idea:

Title: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: hutch-- on October 13, 2014, 08:10:58 PM
You seem to miss it, MASM is not committed to the naming conventions of other compilers and assemblers.
Title: Re: a problem on masm32\m32lib\a2dw.asm win7
Post by: Gunther on October 13, 2014, 08:43:31 PM
Quote from: hutch-- on October 13, 2014, 08:10:58 PM
You seem to miss it, MASM is not committed to the naming conventions of other compilers and assemblers.

Right.  :t That's in principle the freedom and preference of assembly language.

Gunther