NO

Author Topic: MACROS  (Read 1551 times)

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
MACROS
« on: December 30, 2024, 12:40:48 PM »
I try to write a macro creating a window


Code: [Select]
STATIC_CONTROL_CREATION      MACRO   hParent:REQ,X:REQ,_:REQ,W:REQ,H:REQ,lpszTitle:REQ,dwStyle:REQ
mov   [rsp + 40h],hParent
mov   eax,__H
mov   DWORD PTR [rsp + 20h],__X
mov   DWORD PTR [rsp + 28h],__Y
mov   DWORD PTR [rsp + 30h],__W
mov   DWORD PTR [rsp + 38h],eax      ;; H
xor   ecx,ecx
mov   rax,hInstance
mov   DWORD PTR [rsp + 48h],-1
mov   [rsp + 58h],ecx
lea   rdx,szClass_Static + rip
mov   r8,lpszTitle
mov   r9d,dwStyle
mov   [rsp + 50h],rax      ;; hInstance
call   CreateWindowExA
EXITM
ENDM


and I have the error:

Code: [Select]
C:\Users\XXXXXXXXXXXXXXXDocuments\# Assembleur #\Awpe\Awpe.asm(868): error: Expected 'ENDM'.

What is the problem?

I rarely use macros and I am not lucky.
I read the help file and all seemed OK.
Why?
« Last Edit: December 30, 2024, 12:43:53 PM by HellOfMice »
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #1 on: December 30, 2024, 01:19:21 PM »
Hi Philippe,

You don't need EXITM to terminate the macro. ENDM does the job.

Reading Pelles help file :

Quote
The body may contain one or more EXITM directives, making it possible to return a value from the macro. The use of EXITM signals the macro as being a special function-like macro suitable for use in expressions. All tokens following EXITM up to the following line break will be used as the return value.
Code it... That's all...

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #2 on: December 30, 2024, 01:27:34 PM »
Thank you Vortex


The problem was because I had no new line after ENDM
 8)
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #3 on: December 30, 2024, 08:31:21 PM »
Hi Philippe,

You are welcome. Any specific reason to avoid the invoke macro in your code?
Code it... That's all...

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #4 on: December 30, 2024, 08:34:32 PM »
Hi Vortex,

I add the of making a macro or a procedure.
Like I never make macros, I would lie to try

I has 95 windows to create

That's all

Philippe
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #5 on: January 12, 2025, 12:25:38 PM »
Hi Philippe,

Quote
Like I never make macros

I understand your choice but invoke is simplifiying a lot of tedious tasks.
Code it... That's all...

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #6 on: January 12, 2025, 01:20:34 PM »
Hello Vortex,

I agree with you but if the code is not pretty I prefer doing it at the hand.
A thing that we should be able to modify easily is the prolog.
I read a lot of thing about it.
I think that if you want an aligned string or structure we must declare it as a string and then declare a pointer on it but a place it is aligned on a 16 byte boundary.
Example

LOCAL _Lvi:LVITEM becomes

LOCAL _Lvi[2 * SIZEOF LVITEM]:BYTE
LOCAL _lpLvi:LPLVITEM

lea rax,_Lvi
and rax,NOT 15
mov _lpLvi,rax

then only use the pointer
That's very fresh, maybe there are errors in my writing.
I read this from AMD - Optimization - 25112.PDF
https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/40332.pdf
--------------------------------
Kenavo

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2215
Re: MACROS
« Reply #7 on: January 12, 2025, 02:07:51 PM »
What you need for prolog ?
Code: [Select]
WinMainCRTStartup proc this is empty prolog
also some align things are solved with right size LOCALs ?

I don't use asm, expect for fun.
« Last Edit: January 12, 2025, 02:09:31 PM by TimoVJL »
May the source be with you

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #8 on: January 12, 2025, 02:10:20 PM »
hi Timo


Or keeping variables into register rather that stack.
I wonder if it would be a good idea to have a structure into which we have the local variables?
What do you think?
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #9 on: January 12, 2025, 09:15:35 PM »
Hi Philippe,

You could align your structures by calculating their sizes.
« Last Edit: January 13, 2025, 09:33:54 PM by Vortex »
Code it... That's all...

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #10 on: January 14, 2025, 07:54:33 PM »
Hi Philippe,

MASM – Stack Memory Alignment :

http://www.atelierweb.com/index.php/masm-stack-memory-alignment/
Code it... That's all...

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #11 on: January 14, 2025, 08:03:04 PM »
Hello and Thank you Vortex,

I have read (quickly) this post and it is the reason I used structures and delared them as a LOCAL variable like this:

Code: [Select]
STACKPTR_SEARCH_DIRECTORY   STRUCT  8
    lpHeaders           LPPHR_PE_ANALYZER   ?           ;  8
    lpDirectoryAddress  LPSTR               ?           ;  8
    lpszDirectoryName   LPSTR               ?           ;  8
    lpLvi               LPLVITEM            ?           ;  8
    lpszTmp             LPBYTE              ?           ;  8
    lpszVirtualAddress  LPBYTE              ?           ;  8
    lpszVirtualSize     LPBYTE              ?           ;  8
    hListView           HWND                ?           ;  8
STACKPTR_SEARCH_DIRECTORY   ENDS                        ; 64

LPSTACKPTR_SEARCH_DIRECTORY TYPEDEF PTR STACKPTR_SEARCH_DIRECTORY

STACKDATA_SEARCH_DIRECTORY  STRUCT  16
    szTmp               BYTE                128 dup(?)      ; 128
    Lvi                 LVITEM              <>              ;  88
    szVirtualAddress    BYTE                64 dup(?)       ;  64
    szVirtualSize       BYTE                64 dup(?)       ;  64
    dwDirectoryIndex    DWORD               ?               ;   4
STACKDATA_SEARCH_DIRECTORY  ENDS                            ; 348

LPSTACKDATA_SEARCH_DIRECTORY TYPEDEF PTR STACKDATA_SEARCH_DIRECTORY

STACK_SEARCH_DIRECTORY  STRUCT  16
    Data                STACKDATA_SEARCH_DIRECTORY  <>      ; 352
    Pointers            STACKPTR_SEARCH_DIRECTORY   <>      ;  64
STACK_SEARCH_DIRECTORY  ENDS                                ; 416

LPSTACK_SEARCH_DIRECTORY TYPEDEF PTR STACK_SEARCH_DIRECTORY
I hope I have not made errors
Give me your advices and remarks
I use a 16 bye alignment in case I use MMX instructions
I USE ONE STRUCTURE FOR DATAS AND THE OTHERR ONE FOR POINTERS


Philippe
« Last Edit: January 14, 2025, 08:04:39 PM by HellOfMice »
--------------------------------
Kenavo

Offline HellOfMice

  • Member
  • *
  • Posts: 362
  • Never be pleased, always improve
Re: MACROS
« Reply #12 on: January 14, 2025, 08:17:52 PM »
Rather than using structure I thought to use a buffer and computing a 16 bytesd boundary, when found I declare a structure pointer on that position
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #13 on: January 15, 2025, 07:34:39 PM »
Hi Philippe,

Your structures are looking OK. Thr most important is to align properly the members of the structures.
Code it... That's all...

Offline Vortex

  • Member
  • *
  • Posts: 975
    • http://www.vortex.masmcode.com
Re: MACROS
« Reply #14 on: January 19, 2025, 12:26:11 PM »
Hi Philippe,

The quick test below ( excluding the SSE stuff for the moment ) demonstrates that Poasm is successfully aligning the local structures to QWORD boundary.

Code: [Select]
include LocalStructAlign.inc

PRINTPAGERANGE STRUCT

    nFromPage   dd ?
    nToPage     dd ?

PRINTPAGERANGE ENDS


sample STRUCT

    x           db ?
    y           db ?

sample ENDS

.data

a1  db 'OFFSET var1 = %X',13,10,0
a2  db 'OFFSET var2 = %X',13,10,0
a3  db 'OFFSET ppr  = %X',13,10,0
a4  db 'OFFSET s    = %X',13,10,0
a5  db 'OFFSET var3 = %X',13,10,0

.data?

buffer  db 64 dup(?)

.code

start PROC PARMAREA=4*QWORD

    call    main
    invoke  ExitProcess,0

start ENDP


main PROC PARMAREA=4*QWORD

LOCAL var1:QWORD            ; rsp+50H
LOCAL var2:QWORD            ; rsp+48H

LOCAL ppr:PRINTPAGERANGE    ; rsp+38H
LOCAL s:sample              ; rsp+30H

LOCAL var3:QWORD            ; rsp+28H

    invoke  wsprintf,ADDR buffer,ADDR a1,ADDR var1
    invoke  StdOut,ADDR buffer
   
    invoke  wsprintf,ADDR buffer,ADDR a2,ADDR var2
    invoke  StdOut,ADDR buffer
   
    invoke  wsprintf,ADDR buffer,ADDR a3,ADDR ppr
    invoke  StdOut,ADDR buffer
   
    invoke  wsprintf,ADDR buffer,ADDR a4,ADDR s
    invoke  StdOut,ADDR buffer
   
    invoke  wsprintf,ADDR buffer,ADDR a5,ADDR var3
    invoke  StdOut,ADDR buffer
   
    ret

main ENDP

Output on Windows 7 Sp1 :

Code: [Select]
OFFSET var1 = 22FC60
OFFSET var2 = 22FC58
OFFSET ppr  = 22FC48
OFFSET s    = 22FC40
OFFSET var3 = 22FC38
« Last Edit: January 19, 2025, 12:28:35 PM by Vortex »
Code it... That's all...