The MASM Forum

Microsoft 64 bit MASM => Examples => Topic started by: ognil on September 25, 2024, 01:13:56 PM

Title: Re: Macro Definition & usage discussion + supplementary
Post by: ognil on September 25, 2024, 01:13:56 PM
For generic.asm I have the following small notes of his good explanations.
It is not explained in generic.asm what the following macros also do:

1. Invoke
2. ptr$(WndProc)
3. rv(LoadCursor,NULL,IDC_ARROW)
4. .if, .elseif, .endif
5. .if wParam == 1000
6. Why the second .asm file using macros is better than the first one not using macros?

The MACROS explanation needs to be changed to tell the truth.

MACROS is a deprecated method for expanding text during assembly in MASM32. Using them becomes difficult and wastes valuable time for the novice MASM64 programmer. He needs to learn in detail an obsolete high-level language (macros) and then learn MASM64.
MS MASM64 API  does not use macros and allows to programmer clean and convenient way to use COMMON blocks of code with capacity to use DIFFERENT parameters in each block starting with service word "proc" and ending with "endp".

Some forum members mistakenly put an equal sign between Newcomer and Newbie. They wasting Newbie's time with outdated Win32+Macros training without caring about Newbie's  present and future.

The third file is written in a language I do not understand and cannot comment on. Sorry! :nie:

Thank you Zedd151.
Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: sinsi on September 25, 2024, 02:01:33 PM
ognil, I think you need to understand macros a bit better, they're not just "a deprecated method for expanding text during assembly".

There is no such thing as "MS MASM64 API" but there are two different things called "MS API" and "MASM64"

The whole point of MASM64 is to let people ignore the peculiarities of the Win64 ABI and just code.

Don't forget what the first "M" in "MASM" stands for  :biggrin:
Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: NoCforMe on September 25, 2024, 02:09:53 PM
And realize that like one's choice of editor, the use of macros is what they call a religious issue, meaning that some folks have strong opinions one way or the other regarding them, and there are sometimes raging arguments over them. (I come down on the "few to no macros for me, thank you very much" side, while others, like JJ, use them frequently and make them an integral part of their code.)

Like they say, different strokes for different folks ...
Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: ognil on September 26, 2024, 12:08:54 AM
Hi sinsi,

Quoteognil, I think you need to understand macros a bit better...

Interesting thought! I'm Newcomer but not a Newbie and prefer not to waste my time with some pseudo high level language that won't bring me anything in the future. I use this time to improve my C++.

Thanks for opening my eyes to what MS is, but you didn't say what you think the definition of a macro is and why it must be used in assembly programs.

I would appreciate your comment on my macro-free code here:

https://masm32.com/board/index.php?action=dlattach;attach=17529 (https://masm32.com/board/index.php?action=dlattach;attach=17529)
and here:

https://masm32.com/board/index.php?action=dlattach;attach=17511 (https://masm32.com/board/index.php?action=dlattach;attach=17511)

Thank you. :azn:
Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: jj2007 on September 26, 2024, 12:51:18 AM
Quote from: sinsi on September 25, 2024, 02:01:33 PMI think you need to understand macros

I will mark this date in my diary, sinsi ❤️
Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: sinsi on September 26, 2024, 07:38:32 AM
Quote from: ognil on September 26, 2024, 12:08:54 AMbut you didn't say what you think the definition of a macro is
That's for you to discover

Quote from: ognil on September 26, 2024, 12:08:54 AMand why it must be used in assembly programs
Where did I say that they must be used?

Quote from: ognil on September 26, 2024, 12:08:54 AMI would appreciate your comment on my macro-free code here
Macro-free? include  \masm32\include64\masm64rt.inc

Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: NoCforMe on September 26, 2024, 08:14:26 AM
Quote from: ognil on September 26, 2024, 12:08:54 AM[I] prefer not to waste my time with some pseudo high level language that won't bring me anything in the future. I use this time to improve my C++

I'm in agreement here, surprisingly.
Seeing the way some people code with macros here and produce source that looks just like C, with indented if/else blocks and all, I wonder, why are they even bothering with assembly language? Why not just use C? For most purposes it's not going to be noticeably slower or anything ...
Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: ognil on September 26, 2024, 01:09:40 PM
Thanks sinsi,

QuoteMacro-free? include  \masm32\include64\masm64rt.inc

Because it frames and keeps the stack aligned.
Otherwise, for each program I have to write something like:

extern __imp_MessageBoxA:qword
MessageBoxA equ <__imp_MessageBoxA>
.data
caption db "'Macbeth', specifically Act 5, Scene 5",0
text db 'Life is a tale told by an idiot, full of sound and fury, signifying nothing',0

.code
main proc frame
     push rbp
.pushreg  rbp
     sub  rsp, 010h
.allocstack 010h
     mov  rbp, rsp
.setframe rbp, 0
.endprolog
; modify the stack pointer outside of the prologue
     sub  rsp, 060h
;***********************
    xor   r9d, r9d
    lea   r8,  caption
    lea   rdx, text
    xor   rcx, rcx
    call  MessageBoxA
;***********************
add rsp, 060h
add rsp, 010h
pop rbp
ret
main endp
;***********************
end
:smiley:
Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: sinsi on September 26, 2024, 01:21:58 PM
Quote from: ognil on September 26, 2024, 01:09:40 PMBecause it frames and keeps the stack aligned.
Yes by using prologue and epilogue macros.

As for your test program isn't that just an invoke-less copy of one of hutch's examples? Even the variable names are the same.
Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: six_L on September 26, 2024, 02:33:48 PM
Hi, ognil
QuoteLife is a tale told by an idiot, full of sound and fury, signifying nothing.
Sounds fairly the philosophical words.
this showed you acknowledge it. you'r not a master of life, rather than a slave of life.
Chairman Mao said "
QuoteWherever there is oppression, there is counterattack.
"
"
QuoteFighting the sky, the earth, and people,that brings you to an endless enjoyment.
"
Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: ognil on September 27, 2024, 12:37:06 AM
Hi sinsi,

QuoteAs for your test program isn't that just an invoke-less copy of one of hutch's examples? Even the variable names are the same.

The example text is copy-paste-correct from "Examples" without the more important part:
WndProc                proc   
; Save 4 registers here or in global variables                     
                        mov    [rbp+16], rcx                      ; rbp+8=Return address
                        mov    [rbp+24], rdx                       
                        mov    [rbp+32], r8
                        mov    [rbp+40], r9
...
...
@Ret: 
                        lea    rsp,[rbp+8]                        ; rsp=Return address
                        lea    rax,DefWindowProc
; Restore 4 registers from here or from global variables                         
                        mov    r9, [rsp+32]
                        mov    r8, [rsp+24]
                        mov    rdx,[rsp+16]
                        mov    rcx,[rsp+8]
                        jmp    qword ptr [rax]
:smiley:
Title: Re: Re: Macro Definition and usage discussion64 bit examples for beginners
Post by: BugCatcher on September 27, 2024, 01:17:17 AM
Is call a macro or an assembler directive? Hmm.. I'm too sleepy to find out.
Title: Re: Re: Macro Definition & usage discussion + supplementary
Post by: zedd151 on October 07, 2024, 01:18:05 PM
What sinsi said, below this post.  :toothy:

I'm using hutch's and vasily's macros, ognil Professor.
Title: Re: Re: Macro Definition & usage discussion + supplementary
Post by: sinsi on October 07, 2024, 01:43:46 PM
Quote from: ognil on October 07, 2024, 05:46:58 AMGreat idea, but pls, stop using the macros in MASM64
Mate, you are using macros, hutch made invoke, prologue and epilogue macros, which rely on a shitload of other macros. If you are using masm64rt.inc then you are using macros :rolleyes:
Title: Re: Re: Macro Definition & usage discussion + supplementary
Post by: ognil on October 07, 2024, 03:20:57 PM
Hi, sinsi

The creation of this site by Hutch as well as all programs and tools in it must agree the requirements and rules of  the owner - MS.
When the owner(MS) changes software requirements and rules are communicated to users.

In our case with a note in parentheses (32-bit MASM only).

It is not fair to use Hutch's authority and name now that he is no longer with us.
It can be seen that when he created the site with his tools and examples he followed all the rules and requirements of the MS.

The problem is that after him there is no one to update some of his tools (including macros) according to the changed MS rules, in other words to use rules, macros, directives, etc.
without the note (for 32-bit MASM only). :undecided:

Quote:by  zedd151:  quote from ognil


It is from MS not from ognil. :thumbsup:

Title: Re: Re: Macro Definition & usage discussion + supplementary
Post by: NoCforMe on October 07, 2024, 03:50:41 PM
Quote from: ognil on October 07, 2024, 03:20:57 PMthis site [...] must agree the requirements and rules of  the owner - MS.

WTF are you talking about? Microsoft doesn't own this site.

True, the 64-bit SDK available here needs to play by Microsoft's rules (at least those governing assembly language programming), but that's not a concern: it does conform to those rules. Has to, really, by definition, since it uses Microsoft tools to assemble and link programs. As everyone knows, macros happen to be an integral part of the assembler (hence the name). So far as documentation on how to use those macros, that's easily found in the Microsoft Learn document repository.

So none of us here know what you're going on about in this thread. It's one thing to avoid using macros (I do), as that's a personal decision. But to impose that restriction on those who want to learn 64-bit MASM programming? No way, Jose.

And why do you keep sticking "32-bit MASM only" in big red letters in your posts? This thread is about 64-bit programming.
Title: Re: Re: Macro Definition & usage discussion + supplementary
Post by: sinsi on October 07, 2024, 03:54:33 PM
Remove the line include \masm64\include64\masm64rt.inc and let us know how you fare with no macros.
Title: Re: Re: Macro Definition & usage discussion + supplementary
Post by: HSE on October 08, 2024, 12:09:37 AM
Quote from: ognil on September 25, 2024, 01:13:56 PMMACROS is a deprecated method for expanding text during assembly

Not really. Where you found that fallacy?
Title: Re: Re: Macro Definition & usage discussion + supplementary
Post by: stoo23 on October 08, 2024, 07:55:00 PM
I moved these posts here to this New Topic, thinking that perhaps further useful & creative discussion might occur on the Topic but sadly, it seems Not,..

I have attempted to tidy it up and will leave it open, in the hope that further reasonable and civil discussion can occur  :smiley: