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 attached below.

Note: I will be revising some of these examples, with commenting where it is lacking, as time permits... stay tuned! (Or at least check here from time to time  :tongue: )

"We are living in interesting times"   :tongue:

sinsi

Good examples, at least they build without VS  :thumbsup:

One thing that offends my frugal soul :biggrin:
xor rcx, rcxThis does the same thing, but one (!) byte less
xor ecx, ecx
I know it's not a lot, but the number of times we zero a register it can add up.
Hutch and I had an argument about it, he basically said that it's 64-bit, so use 64-bit everywhere :badgrin:
He certainly wasn't a byte counter.


zedd151

#2
Quote from: sinsi on September 29, 2024, 04:18:31 PMOne thing that offends my frugal soul :biggrin:
xor rcx, rcx
Sorry to hear that.  :tongue:  As these are merely 'simple' conversions from Masm32 examples and not a rewrite, I will leave it be. The purpose was to show how easy 64 bit assembly can be using the Masm64 SDK. If you or any other member would like to contribute 64 bit examples here (for beginners) - in your own coding style - you are welcome to do so.  :thumbsup:


"We are living in interesting times"   :tongue:

zedd151

Speaking of "simple conversions from 32 -> 64 bit", I am working on a converter that will (in theory, anyway) convert simple 32 bit programs to 64 bit. I had done this a few years ago, but that source has been discarded since there were a few fatal flaws in that rendition. So, I am proceeding to write a new converter. This should be a great help to my endeavor to make a few more 64 bit examples.   :smiley:  Quicker than writing them from scratch, and there are a ton of such examples in 32 bit already - ripe for conversion. :wink2:

I will be creating a new topic for it, when it is nearly completed.  :biggrin:
"We are living in interesting times"   :tongue:

NoCforMe

Interesting. How exactly would one convert a 32-bit program to 64-bit? Rename 32-bit registers (EAX--> RAX)? Add 64-bit prologues and stack-alignment stuff?
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on October 06, 2024, 05:36:23 AMInteresting. How exactly would one convert a 32-bit program to 64-bit? Rename 32-bit registers (EAX--> RAX)? Add 64-bit prologues and stack-alignment stuff?
something like that. Also adjust indirect addressing for 64 bit among other things.
Ex. [reg32+reg32*4] -> [reg64+reg64*8]
Ex. shl eax, 2 -> shl rax, 3
I have a qe plugin that does some of the work, and began expanding on what the plugin does. It was apparent that a stand alone program might be more useful for others, that brings me to mentioning it here.  :biggrin:
I won't comment much more here, you will have to wait until I post the initial code for more details...  :tongue:

But I will say this much about the beginnings.
When I first delved into 64 bit a few years back, I made a qe plugin that used two lists, old.txt and new.txt. It scans the source until a string on the indexed old list is found, and simply replaces it with the indexed string from the new list. Easy peasy. But then there will be other things that cannot be done via a simple replcement... that need to be changed for masm64. More details when I post the conversion project. I will be working on the project concurrently with converting one of my older programs to 64 bit.
"We are living in interesting times"   :tongue:

NoCforMe

Quote from: zedd151 on October 06, 2024, 05:53:51 AMEx. shl eax, 2 -> shl rax, 3

I don't think so. What if the programmer just wanted to multiply the value in EAX by 4?
Assembly language programming should be fun. That's why I do it.

zedd151

#7
Quote from: NoCforMe on October 06, 2024, 06:16:29 AMI don't think so. What if the programmer just wanted to multiply the value in EAX by 4?
It is all in the context of where it is used. (In that example, multiplying eax by the size of register prior to allocating buffer memory) one of the things I am currently working on. If I cannot do it programmatically (figure out the context) I might use a yes/no message box, to let the user to decide to convert it or not. That is one of the tricky parts.  :azn:  There are a few others that are a bit tricky to do programmatically. Big Phun.  :tongue:
"We are living in interesting times"   :tongue:

NoCforMe

Quote from: zedd151 on October 06, 2024, 06:29:04 AMIf I cannot do it programmatically (figure out the context)

That, my friend, would be really, really complicated. Far more complex than you're probably imagining. For one, you'd have to be able to parse all the code, not just do string comparisons.
Assembly language programming should be fun. That's why I do it.

zedd151

You might be right, but so far no huge issues.  :cool:  I'll just have to wait until I reach a major hurdle.  :biggrin:

Worst that could happen, is that the output source code will have to be checked for errors/discrepancies  visually, and adjusted accordingly. Mind you, I won't be trying to convert complex algorithms or twiddle with the stack at all. The default prologue and epilogue seem to work okay. Remember this is for converting 'simple' examples.  :smiley:
"We are living in interesting times"   :tongue:

jj2007

Quote from: zedd151 on October 06, 2024, 05:07:16 AMI am working on a converter that will (in theory, anyway) convert simple 32 bit programs to 64 bit.

Congrats, ambitious but useful.

Quotethere are a ton of such examples in 32 bit already - ripe for conversion.

Stick to \Masm32\Examples\*.asm

zedd151

Quote from: jj2007 on October 07, 2024, 03:19:36 AMStick to \Masm32\Examples\*.asm
There are some others that I will be looking at as well. But yes, that is where I started. I will revise some of the commenting as necessary as I go along, including the examples already posted here in the first post.

Most likely, I will start posting each example in its own thread rather than posting new ones here scattered among the comments, as the thread would get cluttered - and I don't want to cram the first post with a hundred examples either.  :smiley:
"We are living in interesting times"   :tongue:

ognil

Quoteby zed151: I will revise some of the commenting as necessary as

Great idea, but pls, stop using the macros in MASM64.
Otherwise you'll have to write comments about them too. :badgrin:
"Not keeping emotions under control is another type of mental distortion."

zedd151

#13
Quote from: ognil on October 07, 2024, 05:46:58 AMGreat idea, but pls, stop using the macros in MASM64.
No can do. These are Masm64 examples. In case you have forgotten, or didn't know, the first "M" is for "macro".  :tongue:

The macros are there to make the programmers job easier. You do as you wish to do,  and I will do as I wish to do.  :badgrin:

:biggrin:
This project will continue at some time in the near future.
"We are living in interesting times"   :tongue:

stoo23

#14
This topic was tidied up, with Removed 'posts' Merged with the existing Removed post Topic, here: Re: Macro Definition & usage discussion + supplementary