flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Strange use of STRUC:

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Code:
struc LoadCursor hInstance,lpCursorName {
  . equ ; punt Very Happy
  irp n, IDC_ARROW=32512,IDC_IBEAM=32513,IDC_WAIT=32514,IDC_CROSS=32515,IDC_UPARROW=32516,\
         IDC_SIZE=32640,IDC_ICON=32641,IDC_SIZENWSE=32642,IDC_SIZENESW=32643,IDC_SIZEWE=32644,\
         IDC_SIZENS=32645,IDC_SIZEALL=32646,IDC_NO=32648,IDC_HAND=32649,IDC_APPSTARTING=32650,\
         IDC_HELP=32651 \{
    match A==B,n \\{
      match =A,lpCursorName \\\{
        display \\\`A,"=",\\\`B,13,10
      \\\}
    \\}
  \}

}
      xxx LoadCursor 0,IDC_ARROW
  xxx LoadCursor 0,IDC_WAIT
   xxx LoadCursor 0,IDC_ICON    
Laughing

_________________
¯\(°_o)/¯ unlicense.org
Post 16 Feb 2009, 07:38
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Erm? Not having to define constants? Did you have some namespace collision that you had to solve?
Post 16 Feb 2009, 08:28
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
No just playing down at the coffee shop - wondering how much the preprocessor could do. Think there is a more efficient preprocessor lookup using just match.
Post 16 Feb 2009, 10:18
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
The more efficient version with a single match:
Code:
struc LoadCursor hInstance,lpCursorName {
 . equ ; punt Very Happy

     match A=|=lpCursorName==B=|C,||IDC_ARROW=32512|IDC_IBEAM=32513|IDC_WAIT=32514|IDC_CROSS=32515|IDC_UPARROW=32516|IDC_SIZE=32640|IDC_ICON=32641|IDC_SIZENWSE=32642|IDC_SIZENESW=32643|IDC_SIZEWE=32644|IDC_SIZENS=32645|IDC_SIZEALL=32646|IDC_NO=32648|IDC_HAND=32649|IDC_APPSTARTING=32650|IDC_HELP=32651|| \{
         display `lpCursorName,"=",\`B,13,10
      \}
}    
...of course, the general concept has broad applicability, and the choice of separating character might be less confusing with a colon?
Code:
struc LoadCursor hInstance,lpCursorName {
      . equ ; punt Very Happy

     match A:=lpCursorName==B:C,\
               :\
             :IDC_ARROW  =32512\
            :IDC_IBEAM  =32513\
            :IDC_WAIT   =32514\
            :IDC_CROSS  =32515\
            :IDC_UPARROW        =32516\
            :IDC_SIZE   =32640\
            :IDC_ICON   =32641\
            :IDC_SIZENWSE       =32642\
            :IDC_SIZENESW       =32643\
            :IDC_SIZEWE =32644\
            :IDC_SIZENS =32645\
            :IDC_SIZEALL        =32646\
            :IDC_NO             =32648\
            :IDC_HAND   =32649\
            :IDC_APPSTARTING=32650\
                :IDC_HELP   =32651\
            ::
  \{
            display `lpCursorName,"=",\`B,13,10
      \}
}    
...I was surprised it worked with the whitespace, but it does.
Post 28 May 2009, 06:29
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Here is a more practical example:
Code:
macro R64FromR32 [r64,r32] {
    match A:=r32==B:C,::eax=rax:edx=rdx:ecx=rcx:ebx=rbx:ebp=rbp:esi=rsi:edi=rdi:esp=rsp:r8d=r8:r9d=r9:r10d=r10:r11d=r11:r12d=r12:r13d=r13:r14d=r14:r15d=r15:: \{
              r64 equ B
   \}
}    
I needed the preprocessor to generate the 64-bit register from the 32-bit register for use in addressing, and vice-versa. This will eliminate superfluous prefixes in long-mode, or prevent assembly errors when mixing address register and index register within a macro. It also shows how to return a value from a macro.
Code:
  R64FromR32 MY_REG,eax
       mov eax,[MY_REG]    

Usage back link: http://board.flatassembler.net/topic.php?p=98156#98156
Post 22 Jul 2009, 03:36
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.