Author Topic: Uppercase  (Read 5598 times)

mabdelouahab

  • Member
  • ****
  • Posts: 511
Uppercase
« on: November 13, 2013, 10:13:44 AM »
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

  • Member
  • *****
  • Posts: 13283
  • Assembly is fun ;-)
    • MasmBasic
Re: Uppercase
« Reply #1 on: November 13, 2013, 06:14:59 PM »
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.
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: Uppercase
« Reply #2 on: November 13, 2013, 11:23:20 PM »
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

  • Member
  • *****
  • Posts: 13283
  • Assembly is fun ;-)
    • MasmBasic
Re: Uppercase
« Reply #3 on: November 14, 2013, 01:00:31 AM »
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>
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: Uppercase
« Reply #4 on: November 14, 2013, 01:07:33 AM »
What 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

  • Member
  • ****
  • Posts: 511
Re: Uppercase
« Reply #5 on: November 14, 2013, 04:11:17 AM »
Thank you  qWord,  jj2007 , It's nice of you :t

mabdelouahab

  • Member
  • ****
  • Posts: 511
Re: Uppercase
« Reply #6 on: November 14, 2013, 11:28:05 AM »
Code: [Select]
@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
Code: [Select]
@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
Code: [Select]

@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