Author Topic: converting 32 bit code to 64 bit  (Read 1892 times)

zedd151

  • Member
  • ****
  • Posts: 850
converting 32 bit code to 64 bit
« on: May 19, 2018, 11:20:02 AM »
What are the major differences, and most importantly obstacles for a newcomer to 64 bit asm programming?  I have looked some 64 bit code, and read some very confusing material regarding the subject. So any pointers from someone who successfully has already made such conversions are welcome.

Otherwise I'll probably stick to 32 bit until it becomes obsolete.   :P


My very first 64 bit program. It's a whopper!   :icon_mrgreen:

I don't think this 64 bit stuff will be too hard.   :icon_confused:

edit == add attachment   :biggrin:
« Last Edit: July 19, 2018, 05:32:47 PM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5831
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: converting 32 bit code to 64 bit
« Reply #1 on: May 19, 2018, 02:27:53 PM »
Z,

64 bit in Windows is a different animal under the hood, different calling convention, critical alignment or it won't run and with ML64, its a lower level assembler that is very terse as its not a consumer product. You can also have a look at UASM which is progressing in its capacity if you go to its sub forum.

With small apps, 32 bit code is fine, easily fast enough, well understood and a bit friendlier than 64 bit code. At the other end 64 bit assembler has more registers and is capable of bashing very large amounts of data into shape. The 64 bit version I have been writing where you have to obtain the Microsoft binaries yourself is already application capable and has a reasonable amount of macro support as well as an ever increasing library of its own.

I don't know enough about it to evaluate it but nidud also has another fork from JWASM which you may be interested in looking at.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

zedd151

  • Member
  • ****
  • Posts: 850
Re: converting 32 bit code to 64 bit
« Reply #2 on: May 19, 2018, 02:43:37 PM »
Z,

64 bit in Windows is a different animal under the hood, different calling convention

I found that out while trying to convert one of my proggies to 64 bit, and it just wasn't working the way I thought it should. So I will be doing plenty of reading on 64 assembly. 

Quote
At the other end 64 bit assembler has more registers and is capable of bashing very large amounts of data into shape.
I'm mostly interested in keeping up with the times.

Quote
The 64 bit version I have been writing where you have to obtain the Microsoft binaries yourself is already application capable and has a reasonable amount of macro support as well as an ever increasing library of its own.

Yup, I've already got the 64 bit binaries as well as the masm64 SDK all set to try and make a run for it. I just have to figure a way to reconcile what I know about 32 bit programming with the differences in 64 bit. Thanks for the reply.
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5831
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: converting 32 bit code to 64 bit
« Reply #3 on: May 19, 2018, 02:54:44 PM »
Z,

Have a read of the technical data supplied with the 64 bit version as it has a reasonable amount of detail on how the win64 bit calling convention works. The combined STACKFRAME macros and "invoke" macros (its actually a wrapper for a more generic version) take most of the hack work out of it and you can certainly write no stack frame code once you understand how the calling convention works.

From your 32 bit experience the mnemonics work much the same way, they are just bigger. You have more registers which is a true joy but you must work with the Microsoft 64 bit ABI in terms of registers you must preserve. Also exercise great care with trying to use PUSH / POP as you can mess up the stack alignment and the exe just won't run. Within a stack frame procedure you are better off using locals for preserving registers as you don't risk messing up the stack. Generally a "mov" is faster than a PUSH or POP, it just looks different.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

zedd151

  • Member
  • ****
  • Posts: 850
Re: converting 32 bit code to 64 bit
« Reply #4 on: May 19, 2018, 02:56:51 PM »
@hutch--

 :t

z
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

daydreamer

  • Member
  • ****
  • Posts: 548
  • reach for the stars
Re: converting 32 bit code to 64 bit
« Reply #5 on: May 19, 2018, 04:47:49 PM »
So for coders that prefer fastcall c calling convention and old code style a plot proc designed to use 3 register as x,y,c it must be easier and faster
And once getting used to 64bit coding,you can concentrate on make your code run with newest os and don't worry about xp compatibility
Do you get some size penalty similar to 16/32bit gives you db 66h extra when using mov eax in 16bit mode,mov ax in 32bit mode?
Unicode support standard in 64bit windows? In textarea,messageboxes and other gui stuff?

I prefer 128bit/256bit/512bit coding,even if it's not needed

Quote from Flashdance
Nick  :  When you give up your dream, you die.
*wears a flameproof asbestos suit*

AW

  • Member
  • *****
  • Posts: 1500
  • Let's Make ASM Great Again!
Re: converting 32 bit code to 64 bit
« Reply #6 on: May 19, 2018, 04:56:17 PM »
This is the only thing you need to get started and become a great 64-bit programmer.
https://software.intel.com/en-us/articles/introduction-to-x64-assembly

Alternatively, you can try some go-easy routes and next year you will know exactly as much as you know now (zero).

Mikl__

  • Member
  • ****
  • Posts: 686
Re: converting 32 bit code to 64 bit
« Reply #7 on: May 19, 2018, 06:21:07 PM »
Hi, zedd151!
let's see the content of the topic Examples for Win64 Iczelion tutorial

zedd151

  • Member
  • ****
  • Posts: 850
Re: converting 32 bit code to 64 bit
« Reply #8 on: May 19, 2018, 07:00:14 PM »

let's see the content of the topic Examples for Win64 Iczelion tutorial

I've seen the thread, but didn't have much interest until I got this new computer. Just what a starter in 64 bits needs. Thanks.  :t

@aw27, I have seen that as well during my surfing the net for intelligible info on 64 bit programming in assembly. That's good knowledge there.  :icon14:
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

Mikl__

  • Member
  • ****
  • Posts: 686
Re: converting 32 bit code to 64 bit
« Reply #9 on: May 19, 2018, 07:53:24 PM »
Quote
Just what a starter in 64 bits needs
zedd151,
but you ask and I will answer to you. And I warn you right away, my English is is the worst, only via google-translator

LordAdef

  • Member
  • ****
  • Posts: 590
Re: converting 32 bit code to 64 bit
« Reply #10 on: May 22, 2018, 02:19:51 AM »
Hey Hutch,
How is your development of the 64bit Masm? I tend to be far away from the Masm 64, since I'm still learning the 32 one. Is it progressing as you expect?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5831
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: converting 32 bit code to 64 bit
« Reply #11 on: May 22, 2018, 02:42:39 AM »
Alex,

It is already application capable, has a large collection of macros and about 110 library modules. It is fully Microsoft ABI compliant, uses the correct calling convention and you can use it to do more or less anything you like. I have some documentation done but its a really tedious task while I keep adding to the library but the source code for the modules contain most of the required data.

You can convert 32 to 64 bit but you must understand both to do it. Both Win64 and ML64 are highly intolerant so its a bit harder to get working but it has its advantages, more registers and will handle very large data if you need to. You can get a lot of the code to look very similar and the mnemonics work mush the same way but it is a different animal under the hood, you can code applications with it at very low level but its a pain to do with the complexity of the calling convention.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

felipe

  • Member
  • ****
  • Posts: 943
  • Eagles are just great!
Re: converting 32 bit code to 64 bit
« Reply #12 on: May 23, 2018, 01:44:01 PM »
This is the only thing you need to get started and become a great 64-bit programmer.
https://software.intel.com/en-us/articles/introduction-to-x64-assembly

Quote
RIP-relative addressing: this is new for x64 and allows accessing data tables and such in
the code relative to the current instruction pointer, making position independent code
easier to implement.
MOV AL, [RIP] ; RIP points to the next instruction aka NOP
NOP

 :greenclp:

Quote
Unfortunately, MASM does not allow this form of opcode

 :(
Felipe.

AW

  • Member
  • *****
  • Posts: 1500
  • Let's Make ASM Great Again!
Re: converting 32 bit code to 64 bit
« Reply #13 on: May 23, 2018, 05:10:51 PM »
Quote
:(
It is propaganda, nobody needs that, MASM embeds RIP-relative addressing implicitly.
But for those who are using that as an excuse they have various alternatives. This is possibly the smallest one:

lea rax, [$+7]

and rax points to the next instruction.

felipe

  • Member
  • ****
  • Posts: 943
  • Eagles are just great!
Re: converting 32 bit code to 64 bit
« Reply #14 on: May 24, 2018, 03:48:01 AM »
AW, no more excuses to me, i'm putting my head into 64 bits right now!  But, of course, i'm just beginning...Why plus 7, shouldn't be plus 8?  :shock:
Felipe.