News:

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

Main Menu

A golden older off the Intel site in ML64.

Started by hutch--, July 04, 2016, 11:22:44 AM

Previous topic - Next topic

hutch--




; Sample x64 Assembly Program
; Chris Lomont 2009 www.lomont.org

    OPTION DOTNAME
    option casemap:none

    include \masm64\include\win64.inc
    include \masm64\include\kernel32.inc
    include \masm64\include\user32.inc

    includelib \masm64\lib\kernel32.lib
    includelib \masm64\lib\user32.lib

  .data
    caption db '64-bit hello!', 0
    message db 'Hello World!', 0

  .code

Start PROC
    sub    rsp,28h      ; shadow space, aligns stack
    mov    rcx, 0       ; hWnd = HWND_DESKTOP
    lea    rdx, message ; LPCSTR lpText
    lea    r8,  caption ; LPCSTR lpCaption
    mov    r9d, 0       ; uType = MB_OK
    call   MessageBox   ; call MessageBox API function
    mov    ecx, eax     ; uExitCode = MessageBox(...)
    call ExitProcess
Start ENDP
End


The batch file to build it.


@echo off

\masm64\bin\ml64.exe /c demo.asm

\masm64\bin\link.exe /SUBSYSTEM:WINDOWS /ENTRY:Start /LARGEADDRESSAWARE demo.obj

dir demo.exe

pause

habran

Hi hutch,
I have tested this one and it works fine in release mode but brakes in debug mode with this error message:
QuoteThe procedure entry point BaseProcessInitPostimport could not be located in the dynamic link library
I have built it with VS Community 2013
Cod-Father

hutch--

Hi habran,

This example was one of the earliest ones I found, it ran but was of little use. It took  a long series of test pieces in conjunction with a disassembler to get a reliable system that comprised of a prologue/epilogue pair and call automation that was free of stack twiddling.

habran

My intention was not to attack you, I just wanted to have one simple piece of code which i can use to compare with hjwasm and can be tested with debugger.
Maybe you have some other "Hello world" that can be run in debug mode?
Cod-Father

hutch--

Is this any use ? This is about the simplest example I can think of. Attached file has the build batch file.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    conout "Arrrrgh, G'Day",lf,lf
    waitkey

    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

comment *

.text:0000000140001000 C8800000                   enter 0x80, 0x0
.text:0000000140001004 4883EC60                   sub rsp, 0x60
.text:0000000140001008 488B0D60100000             mov rcx, qword ptr [0x14000206f]
.text:000000014000100f E84C000000                 call sub_140001060
.text:0000000140001014 488B0D5F100000             mov rcx, qword ptr [0x14000207a]
.text:000000014000101b E840000000                 call sub_140001060
.text:0000000140001020 488B0D5E100000             mov rcx, qword ptr [0x140002085]
.text:0000000140001027 E834000000                 call sub_140001060
.text:000000014000102c 488B0D7A100000             mov rcx, qword ptr [0x1400020ad]
.text:0000000140001033 E828000000                 call sub_140001060
.text:0000000140001038 488B0D79100000             mov rcx, qword ptr [0x1400020b8]
.text:000000014000103f E81C000000                 call sub_140001060
.text:0000000140001044 E897000000                 call sub_1400010e0
.text:0000000140001049 48C7C100000000             mov rcx, 0x0
.text:0000000140001050 FF15CA110000               call qword ptr [ExitProcess]
.text:0000000140001056 C9                         leave
.text:0000000140001057 C3                         ret
.text:0000000140001058 CC                         int3
.text:0000000140001059 CC                         int3
.text:000000014000105a CC                         int3
.text:000000014000105b CC                         int3
.text:000000014000105c CC                         int3
.text:000000014000105d CC                         int3
.text:000000014000105e CC                         int3
.text:000000014000105f CC                         int3

sub_140001060   proc
.text:0000000140001060                            local local_1: qword ; [rsp+0x20]
.text:0000000140001060
.text:0000000140001060 C8800000                   enter 0x80, 0x0
.text:0000000140001064 4883EC70                   sub rsp, 0x70
.text:0000000140001068 4C8925AD100000             mov qword ptr [0x14000211c], r12
.text:000000014000106f 4C892DAE100000             mov qword ptr [0x140002124], r13
.text:0000000140001076 4C8935AF100000             mov qword ptr [0x14000212c], r14
.text:000000014000107d 4C8BE1                     mov r12, rcx
.text:0000000140001080 48C7C1F5FFFFFF             mov rcx, -0xb
.text:0000000140001087 FF159B110000               call qword ptr [GetStdHandle]
.text:000000014000108d 4C8BE8                     mov r13, rax
.text:0000000140001090 498BC4                     mov rax, r12
.text:0000000140001093 4883E801                   sub rax, 0x1
.text:0000000140001097
.text:0000000140001097 0x140001097:
.text:0000000140001097 4883C001                   add rax, 0x1
.text:000000014000109b 803800                     cmp byte ptr [rax], 0x0
.text:000000014000109e 75F7                       jne 0x140001097
.text:00000001400010a0 492BC4                     sub rax, r12
.text:00000001400010a3 4C8BF0                     mov r14, rax
.text:00000001400010a6 498BCD                     mov rcx, r13
.text:00000001400010a9 498BD4                     mov rdx, r12
.text:00000001400010ac 4D8BC6                     mov r8, r14
.text:00000001400010af 4C8D4D90                   lea r9, [rbp-0x70]
.text:00000001400010b3 48C744242000000000         mov qword ptr [local_1], 0x0
.text:00000001400010bc FF156E110000               call qword ptr [WriteFile]
.text:00000001400010c2 488B4590                   mov rax, qword ptr [rbp-0x70]
.text:00000001400010c6 4C8B254F100000             mov r12, qword ptr [0x14000211c]
.text:00000001400010cd 4C8B2D50100000             mov r13, qword ptr [0x140002124]
.text:00000001400010d4 4C8B3551100000             mov r14, qword ptr [0x14000212c]
.text:00000001400010db C9                         leave
.text:00000001400010dc C3                         ret
sub_140001060   endp

; --------------------------------------------------------------------------
; sub_1400010e0
; --------------------------------------------------------------------------
sub_1400010e0   proc
.text:00000001400010e0 C8800000                   enter 0x80, 0x0
.text:00000001400010e4 4883EC60                   sub rsp, 0x60
.text:00000001400010e8 48C7C1F6FFFFFF             mov rcx, -0xa
.text:00000001400010ef FF1533110000               call qword ptr [GetStdHandle]
.text:00000001400010f5 488BC8                     mov rcx, rax
.text:00000001400010f8 FF153A110000               call qword ptr [FlushConsoleInputBuffer]
.text:00000001400010fe
.text:00000001400010fe 0x1400010fe:
.text:00000001400010fe 48C7C101000000             mov rcx, 0x1
.text:0000000140001105 48C7C200000000             mov rdx, 0x0
.text:000000014000110c FF152E110000               call qword ptr [SleepEx]
.text:0000000140001112 FF1538110000               call qword ptr [_kbhit]
.text:0000000140001118 4885C0                     test rax, rax
.text:000000014000111b 74E1                       je 0x1400010fe
.text:000000014000111d FF1535110000               call qword ptr [_getch]
.text:0000000140001123 C9                         leave
.text:0000000140001124 C3                         ret
sub_1400010e0   endp

*

habran

Unfortunately, I can not build it :(
I had earlier version of masm32 installed on my D disc but it did not contain include64\masm64rt.inc
so, I downloaded it again and installed. I have recently downloaded masm64 and put on the same disc, however, i've get this:
ml64test.asm(3): fatal error A1000: cannot open file : masm64rt.inc
Cod-Father

hutch--

This is the file but it sounds like the rest of the system is not set up either. While I am working on the project it is a bit all over the place as some of its content is subject to change. It needs the 64 bit includes and libraries and the Microsoft binaries, ML64, LINK and RC. I am using the versions from VS2017.

"masm64rt.inc"


    OPTION DOTNAME                          ; required for macro files
    option casemap:none                     ; case sensitive

    include \masm32\include64\win64.inc     ; main include file
    include \masm32\macros64\vasily.inc     ; main macro file
    include \masm32\macros64\macros64.inc   ; auxillary macro file

    STACKFRAME                              ; create a default stack frame

    include \masm32\m64lib\m64lib.inc       ; include file for m64lib library

  ; ------------------------
  ; system API include64 files
  ; ------------------------
    include \masm32\include64\kernel32.inc
    include \masm32\include64\user32.inc
    include \masm32\include64\gdi32.inc
    include \masm32\include64\Comctl32.inc
    include \masm32\include64\comdlg32.inc
    include \masm32\include64\shell32.inc
    include \masm32\include64\oleaut32.inc
    include \masm32\include64\ole32.inc
    include \masm32\include64\msvcrt.inc
    include \masm32\include64\Shlwapi.inc
    include \masm32\include64\gdiplus.inc

    includelib \masm32\m64lib\m64lib.lib    ; m64lib library

  ; ------------------------
  ; system API library files
  ; ------------------------
    includelib \masm32\lib64\kernel32.lib
    includelib \masm32\lib64\user32.lib
    includelib \masm32\lib64\gdi32.lib
    includelib \masm32\lib64\Comctl32.lib
    includelib \masm32\lib64\comdlg32.lib
    includelib \masm32\lib64\shell32.lib
    includelib \masm32\lib64\oleaut32.lib
    includelib \masm32\lib64\ole32.lib
    includelib \masm32\lib64\msvcrt.lib
    includelib \masm32\lib64\Shlwapi.lib
    includelib \masm32\lib64\gdiplus.lib


habran

Thanks hutch,  :biggrin:
However, there is missing to many things, I am not able to build it with files you supplied. :(
I am wondering if anyone except you succeeded to build anything.
Again, I am not trying to be rude, or to make you look stupid, I like competition and I appreciate your efforts.
Iwould like to have it running so that I can compare two assemblers output.

best regards  :biggrin: 
Cod-Father

habran

Don't worry, I have succeeded to build Win64_3 from JWasm-HJWasm samples which is included in HJWasm download :t
Cod-Father

hutch--

The problem is I have posted things in bits and pieces but have not put it all together as a single package as it is still in development. The logic is install the 32 bit MASM32 SDK then add the stuff I have posted which gives you the include files, the library files, example code, code generation templates and a basic help file. You need to get the Microsoft binaries from Microsoft as I am not licenced to distribute them.

TWell

In my tests ml64.exe with -Zi create bad object-file for linkers from that demo.asm.
I tested versions v.10 and v.14.10.
Huge symbol table, all Windows functions?

I didn't find any debugger that can load that exe for debugging :(

hutch--

I have found that ArkDasm will step through an assembled EXE file but I doubt it would handle Microsoft symbols.

BugCatcher


TWell

I got with version with debug info\masm64\bin\ml64.exe /c /Zi demo.asm
\masm64\bin\link.exe /SUBSYSTEM:WINDOWS /ENTRY:Start /LARGEADDRESSAWARE /DEBUG demo.obj /OUT:demo_dbg.exe


DLL Loaded: 00007FF853E00000 C:\Windows\System32\KernelBase.dll
DLL Loaded: 00007FF854570000 C:\Windows\System32\user32.dll
DLL Loaded: 00007FF8546F0000 C:\Windows\System32\gdi32.dll
DLL Loaded: 00007FF853E00000 C:\Windows\System32\KernelBase.dll
DLL Loaded: 00007FF854570000 C:\Windows\System32\user32.dll
DLL Loaded: 00007FF8546F0000 C:\Windows\System32\gdi32.dll
EXCEPTION_DEBUG_INFO:
           dwFirstChance: 1
           ExceptionCode: C0000139 (STATUS_ENTRYPOINT_NOT_FOUND)
          ExceptionFlags: 00000001
        ExceptionAddress: 00007FF856A3CDD0 ntdll.00007FF856A3CDD0
        NumberParameters: 0
First chance exception on 00007FF856A3CDD0 (C0000139, STATUS_ENTRYPOINT_NOT_FOUND)!
x64dbg.exe read pdb-file too :t