News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Uppercase

Started by mabdelouahab, November 13, 2013, 10:13:44 AM

Previous topic - Next topic

mabdelouahab

Hello to all forum members
I have to admit that I find valuable assistance in this forum ...

I'm not new to programming, but I'm a newbie on the MASM32, I just wanted to be, re-writing the previous programme VB.NET, in the form MASM32, But when it comes to large programs, it becomes difficult to review.
So
I saw that  I need to programming Objects, for that I used Object.inc , And to I Shorten the large lines, I created some MACRO
I need some help, to improve
I hope that the idea has arrived, because I do not perfected English Sory ...

I created the following:
For example, if I wanted to make Object Person, I type the following:

PARCIALCLASS Person
   VAR Birth
   VAR Name_
      VAR Parent
      
     Function AgeAccount
   EndFunction

   Function ImageInput,hBitmap:DWORD
   EndFunction
   
ENDPARCIAL


And the MACRO group auto generate the next CODE:

IFNDEF _Person_
_Person_ equ 1

   Person_Init    PROTO  :DWORD

   Pers_destructorPto    TYPEDEF  PROTO  :DWORD
   Pers_AgeAccountPto    TYPEDEF  PROTO  :DWORD
   Pers_ImageInputPto    TYPEDEF  PROTO  :DWORD, :DWORD

   CLASS Person, Pers
      CMETHOD destructor   
      CMETHOD AgeAccount     
      CMETHOD ImageInput   
      Birth     dd    ?
      Name_     dd    ?
      Parent    dd    ?
   Person ENDS

.data

   BEGIN_INIT
      dd offset Pers_destructor_Funct
      dd offset Pers_AgeAccount_Funct
      dd offset Pers_ImageInput_Funct
      dd 0
      dd a
      dd a
   END_INIT

.code

Person_Init  PROC uses edi esi lpTHIS:DWORD
   SET_CLASS Person
   SetObject edi, Person

   ReleaseObject edi
   ret
Person_Init ENDP

Pers_destructor_Funct  PROC uses edi lpTHIS:DWORD
   SetObject edi, Person

   ReleaseObject edi
   ret
Pers_destructor_Funct  ENDP

Pers_AgeAccount_Funct  PROC uses edi lpTHIS:DWORD
   SetObject edi, Person

   ReleaseObject edi
   ret
Pers_AgeAccount_Funct  ENDP

Pers_ImageInput_Funct  PROC uses edi lpTHIS:DWORD, A:DWORD
   SetObject edi, Person

   ReleaseObject edi
   ret
Pers_ImageInput_Funct  ENDP

ENDIF


I can easily Amendment.
I'm not need to create INIT or DESTRUCTOR Proc, write them down are automatically,I can add NEW or DESTRUCT function , are automatically called up
I can use: VAR V1, or VAR V2,DWORD or VAR V3,BYTE,1
I can INHERITS
BUT
I can not tell the difference between:NEW,New,new, ... (I need a macro like UPPERCASE)
I can not remove the space (I need a macro like Likeas LTrim),
where when I used: GET eax = PersonA.Birth => I happen error,  Must use GET eax =PersonA.Birth with no space between " = " and  " PersonA " 


Wait for your help, I thank you all

jj2007

Quote from: mabdelouahab on November 13, 2013, 10:13:44 AM
I need a macro like UPPERCASE
I need a macro like Likeas LTrim

MasmBasic has both Upper$() and Trim$(), but these are runtime functions - you need assembly time macros. Check the Masm documentation for FORC - together with SUBSTR startpos, endpos, it will do what you need.

qWord

If the text that should be trimmed does not contain commas, the FOR loop could be used:

Quote@TrimStr macro txt:=<>
   ts_txt TEXTEQU <>
   FOR _arg_,<&txt>
      ts_txt TEXTEQU <&_arg_>
   ENDM
   EXITM ts_txt
endm
MASM removes leading and trailing spaces for _arg_.

To get upper case:

Quote; by qWord, 2013
@ToUpperCase macro txt:=<>
   tlc_txt TEXTEQU <>
   FORC char,<&txt>
      tlc_pos INSTR 1,<abcdefghijklmnopqrstuvwxyz>,<&char>
      IF tlc_pos
         tlc_txt TEXTEQU tlc_txt,@SubStr(<ABCDEFGHIJKLMNOPQRSTUVWXYZ>,%tlc_pos,1)
      ELSE
         tlc_txt TEXTEQU tlc_txt,<&char>
      ENDIF
   ENDM
   EXITM tlc_txt
endm
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Just for curiosity (honestly - you know more about macros than I do): Why are you using the ampersand inside <brackets>, and a default empty string like :=<>?

; by qWord, 2013
@ToUpperCase macro txt:=<>
   tlc_txt TEXTEQU <>
   FORC char,<&txt>

; same result:
@ToUpperCase macro txt
   tlc_txt TEXTEQU <>
   FORC char,<txt>

qWord

Quote from: jj2007 on November 14, 2013, 01:00:31 AMWhat is the advantage of using the ampersand inside <brackets>, and a default empty string like :=<>?
Its just for better readability. I use default stings to indicate that the macro work with text/strings (and also blank ones).
MREAL macros - when you need floating point arithmetic while assembling!

mabdelouahab

Thank you  qWord,  jj2007 , It's nice of you :t

mabdelouahab


@TrimString  macro txt:=<>
   ts_txt TEXTEQU <>
   FORC _arg_,<txt>
         tlc_pos INSTR 1,<  >,<_arg_>
      IFE tlc_pos
      ts_txt TEXTEQU ts_txt,<_arg_>
      ENDIF
   ENDM
   EXITM ts_txt
endm


@ToUpperCase macro txt:=<>
   tlc_txt TEXTEQU <>
   FORC char,<&txt>
      tlc_pos INSTR 1,<abcdefghijklmnopqrstuvwxyz>,<&char>
      IF tlc_pos
         tlc_txt TEXTEQU tlc_txt,@SubStr(<ABCDEFGHIJKLMNOPQRSTUVWXYZ>,%tlc_pos,1)
      ELSE
         tlc_txt TEXTEQU tlc_txt,<&char>
      ENDIF
   ENDM
   EXITM tlc_txt
endm



@TrimUPString  macro txt:=<>
   ts_txt TEXTEQU <>
   FORC _arg_,<txt>
         tlc_pos INSTR 1,<  >,<_arg_>
      IFE tlc_pos
      tlc_pos2 INSTR 1,<abcdefghijklmnopqrstuvwxyz>,<&_arg_>
      IF tlc_pos2
         ts_txt TEXTEQU ts_txt,@SubStr(<ABCDEFGHIJKLMNOPQRSTUVWXYZ>,%tlc_pos2,1)
      ELSE
         ts_txt TEXTEQU ts_txt,<&_arg_>
      ENDIF
      ENDIF
   ENDM
   EXITM ts_txt
endm



Thank you  qWord,  jj2007