News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ASC() macro

Started by Ficko, June 21, 2010, 07:25:57 AM

Previous topic - Next topic

Ficko

I got the basic idea somewhere on the board but seems very clumsy. :P

Is a better way to do it?

If not how I get it work on JWASM? ::)


; ------------------------------
ASC$ MACRO _Char:REQ
LOCAL CharPos,Upp
_PhraseUpper TEXTEQU <  !! !" !# !$ !% !& !' !( !) !* !+ !, !- !. !/ 0 1 2 3 4 5 6 7 8 9 !: !; !< != !> !? !@ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ![ !\ !] !^ !_ !`>
_PhraseLower TEXTEQU <  !! !" !# !$ !% !& !' !( !) !* !+ !, !- !. !/ 0 1 2 3 4 5 6 7 8 9 !: !; !< != !> !? !@ a b c d e f g h i j k l m n o p q r s t u v w x y z !{ !| !} !~>
_MirrorASCII TEXTEQU <3233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596>
_RetNum    TEXTEQU <>
CharPos INSTR 1,_PhraseUpper,<_Char>
IF CharPos
EXITM @SubStr(<%_MirrorASCII>,CharPos,2)
ELSE
CharPos INSTR 1,_PhraseLower,<_Char>
IF CharPos
Upp SUBSTR _MirrorASCII,CharPos,2
Upp TEXTEQU %Upp + 32
EXITM Upp
ELSE
.ERR <Illegal ASCII value (_Char) !!>
ENDIF
ENDIF 
ENDM
; -------------

qWord

also works with jwasm:
ASC$ macro chr:req
EXITM %('&chr')
endm

:bg
FPU in a trice: SmplMath
It's that simple!

Ficko

Quote from: qWord on June 21, 2010, 12:26:19 PM
also works with jwasm:
ASC$ macro chr:req
EXITM %('&chr')
endm


Cool thanks! :U

I knew I am overcomplicating the sh*!? :bg

Ficko

Is there a way to get the ASC value from reserved chars too ? ::)

This fails:

.686p
.model flat, stdcall
option casemap :none
ASC MACRO chr:req
EXITM %('&chr')
ENDM
Pilot MACRO CharArray:REQ
%FORC OneChar,<CharArray>
%echo OneChar
%echo ASC(OneChar)
ENDM
ENDM

.code
start:
Pilot "Test String"
end start

Ficko

Damn!!
I thought I have it but doesn't work. :(

What I am missing ? ::)


.686p
.model flat, stdcall
option casemap :none
ASC MACRO chr:req
LOCAL Chr_
Chr_ SUBSTR <chr>,2,1
%echo Chr_
EXITM %('Chr_')
ENDM

Pilot MACRO CharArray:REQ
%FORC OneChar,<CharArray>
%echo ASC('&OneChar&')
ENDM
ENDM

.code
start:
Pilot "Test String"
end start

Ficko

Ok what I am working on is the modification of qWord's Macro:
http://www.masm32.com/board/index.php?topic=14150.msg112342#msg112342

I wan't to use Hash values created from the chars ASC value instead of defining the whole string.

@CatStr(<defs_str_>,%ds_glb_cntr) TEXTEQU CreateHash(&str)

Since I can't figure out a uniformly working ASC MACRO thought just filter out the chars not suitable.:


.686p
.model flat, stdcall
option casemap :none

ASC MACRO chr:REQ
EXITM %('&chr')
ENDM

Pilot MACRO CharArray:REQ
%FORC OneChar,<CharArray>
IFNB <OneChar>
IFDIF <OneChar>,<!">
IFDIF <OneChar>,<!%>
IFDIF <OneChar>,<!'>
IFDIF <OneChar>,<!(>
IFDIF <OneChar>,<!)>
IFDIF <OneChar>,<!,>
IFDIF <OneChar>,<!<>
IFDIF <OneChar>,<!>>
%echo ASC(OneChar) OK
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDM
ENDM

.code
start:
Pilot "!# !$ !% !& !' !( !) !* !+ !, !- !. !/ 0 1 2 3 4 5 6 7 8 9 !: != !? !@ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ![ !\ !] !^ !_ !` !{ !| !} !~"
end start


Any suggestion ? ::)

qWord

Quote from: Ficko on July 01, 2010, 10:58:53 AMI wan't to use Hash values created from the chars ASC value instead of defining the whole string
Did you plan to use these Hash-Values at runtime? However, declaring an TEXTEQU is clearly faster than calculating an Hash.
FPU in a trice: SmplMath
It's that simple!

Ficko

Quote from: qWord on July 01, 2010, 12:33:49 PM
Did you plan to use these Hash-Values at runtime?

No I wan't it assembler time.

Quote
However, declaring an TEXTEQU is clearly faster than calculating an Hash.

Yes it is but MASM has a limit on the lenght and if I use long strings it gives me errors ::)

qWord

Quote from: Ficko on July 01, 2010, 01:36:01 PM
Yes it is but MASM has a limit on the lenght and if I use long strings it gives me errors ::)
simple fix:
def_str macro _label:req,str:VARARG
    LOCAL lbl
    IFNDEF ds_glb_cntr
        ds_glb_cntr = 0
    ENDIF
   
    defs_cntr = 0
    defs_flag = 0
    REPEAT ds_glb_cntr
    ds_txt TEXTEQU @CatStr(<defs_str_>,%defs_cntr)
        IFIDNI ds_txt,<&str>
            defs_flag = 1
            EXITM               
        ENDIF
        defs_cntr = defs_cntr + 1
    ENDM
    IF defs_flag
        .data
            lbl LABEL BYTE
            org @CatStr(<defs_lbl_>,%defs_cntr)
            _label LABEL BYTE
            org lbl
        .code
    ELSE
        @CatStr(<defs_lbl_>,%ds_glb_cntr) TEXTEQU <&_label>
        @CatStr(<defs_str_>,%ds_glb_cntr) TEXTEQU <&str>
        .data
            _label db &str
        .code
        ds_glb_cntr = ds_glb_cntr + 1
    ENDIF       
endm

This macro  supports strings up to ~250 char.
FPU in a trice: SmplMath
It's that simple!

Ficko

Quotesimple fix:

I don't know what the fix is?
Both of your versions are the same doing ~250 chars. :U

I must have made some misstake by the implementation of mine doing much less than that. :eek
Have to go over it again.

Any Idea to the ASC modification above http://www.masm32.com/board/index.php?topic=14254.msg114096#msg114096  ::)

qWord

Quote from: Ficko on July 01, 2010, 02:45:08 PMI don't know what the fix is?
just thought, that the line:
%   IFIDNI <@CatStr(<defs_str_>,%defs_cntr)>,<&str>
cause the problem - I've split it in two lines. However, as you noticed, there is not differenc  :lol
FPU in a trice: SmplMath
It's that simple!