Programming 64-bit applications

The 64-bit Windows operating systems use the fastcall calling convention, that is, when calling a function the first four parameters are passed in the Rcx, Rdx, R8 and R9 registers, respectively, and all parameters are expected to be 8-byte values (QWORD). When writng a 64-bit window procedure, you have to save the four mentioned registers in the corresponding arguments (except for the GoAsm assembler), that is, Rcx in 1st argument, Rdx in 2nd argument, R8 in 3rd argument and R9 in 4th argument. The rest of arguments, if more than four, are passed on the stack.

wndMainProcedure Proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD
    Mov hWnd, Rcx  ;Not needed for GoAsm
    Mov uMsg, Rdx  ;Not needed for GoAsm
    Mov wParam, R8 ;Not needed for GoAsm
    Mov lParam, R9 ;Not needed for GoAsm

wndMainProcedure EndP

REMARKS: Note that the lines above are written in MASM syntax. Please take into account to make the necessary syntax conversion when programming with other assemblers.

You have to mostly use the 64-bit registers in applications (Rax, Rbx, Rcx, Rdx, etc.), and the Rsp register (the stack pointer) has to be always 16-byte aligned when calling an API function, otherwise the application will probably crash. The best you can do in order to get into 64-bit programming, is to have a deep look at the various Easy Code 64-bit examples, located at the \EasyCode\Examples folder.

There are some important considerations that you should take into account when writing code inside a 64-bit procedure (or a frame in GOASM syntax):

There is very liitle 64-bit example code in the internet and it is extremely simple, or in some cases it does not work. All the Easy Code 64-bit support is due to the hard work of my good friend Héctor A. Medina. Without his help, I would not have been able to program the 64-bit examples included in Easy Code.

However, despite the complexity of 64-bit programming, you will get surprised on how Easy Code makes it much easier. Thanks for using Easy Code and good luck!