News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

64 bit examples for beginners

Started by zedd151, September 25, 2024, 05:32:30 AM

Previous topic - Next topic

zedd151

During one of my infrequent ventures into 64 bit programming, I had converted a few examples from the Masm32 SDK to 64 bit. I am sharing them here to help beginners to masm 64 bit assembly  'get their feet wet' using the Masm64 SDK.  :biggrin:

Use the included batch files to build the programs (recommended).

I am assuming that the user has the Masm64 SDK installed (in the root of the drive where the examples also reside somewhere on the same drive where the Masm64 SDK is installed), and has the necessary Microsoft binaries there in the bin64 folder (ml64.exe, link.exe and its associated required dll's).
Visual Studio is not necessary to create or build assembly (*.asm) files, but the binaries may be copied from an existing VS installation. (Easiest way to obtain them)

1. minimum64 - a simple message box example.

2. generic64 - simple generic window example.

3. smalled64 - a small text editor example.

All three beginner level examples are included in the zip file.
I may update This Post with additional examples in the near future.
"We are living in interesting times"   :tongue:

ognil

Congratulations Zedd151, for publishing his 32-bit code translated to 64-bit code. :thumbsup:

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.
"Not keeping emotions under control is another type of mental distortion."

sinsi

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:

NoCforMe

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 ...
Assembly language programming should be fun. That's why I do it.

ognil

#4
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
and here:

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

Thank you. :azn:
"Not keeping emotions under control is another type of mental distortion."

jj2007

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 ❤️

sinsi

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


NoCforMe

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 ...
Assembly language programming should be fun. That's why I do it.

ognil

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:
"Not keeping emotions under control is another type of mental distortion."

sinsi

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.

six_L

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.
"
Say you, Say me, Say the codes together for ever.

stoo23

#11
What a great Shame, that once again, like so Many posts on this forum, a simple post in a topic initially designed for Beginners has been turned into a 'Mess' !!

If there is a Valid discrepancy or incorrect example used / provided in examples posted (for Beginners), it would seem both Prudent and Appropriate to MAKE additional suggestions and examples in a Cordial and informative fashion, in Respect of BOTH the Original Poster and the Beginner reading the thread, with NO further Inter-Personal comments or Opinions regarding the OP or Other members.

If there IS a serious disagreement regarding the Quality or relevance / suitability of the post or information presented therein,.. then we have a very capable PM system to communicate that information to the OP, for private discussion and hopeful resolution etc.

Perhaps, much like posts in the Campus,.. inherently useful educational Topics, should NOT contain arguments or extraneous posts that Add nothing for the person wanting to actually learn something by reading the post.

By all means Add further valid or additional / different examples but leave the Non Code inter-personal opinions out.


ognil

Thank you Admin!

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:
"Not keeping emotions under control is another type of mental distortion."

BugCatcher

Is call a macro or an assembler directive? Hmm.. I'm too sleepy to find out.