News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Breakthrough!! Masm64: hello world

Started by Sarel, March 21, 2011, 02:02:23 PM

Previous topic - Next topic

Sarel

This might not be so great but it took me very long to get it assembled and linked. So this is for all of us that would like to try 64 bit programs using masm64. The next bit comes from jwasm site.

;--- Win64 "hello world" GUI application.
;--- Note: requires at least JWasm v2
;--- assemble: JWasm -win64 Win64_1.asm
;--- link:     Link /subsystem:windows /entry:main Win64_1.obj

   option casemap:none

   includelib c:\masm64\lib\kernel32.lib               ;added the c:\masm64\lib\
   includelib c:\masm64\lib\user32.lib                 ;added the c:\masm64\lib\

externdef MessageBoxA : near
externdef ExitProcess : near

   .data

text    db 'Hello world!', 0
caption db 'Hello x86-64', 0

   .code

main proc
   sub rsp, 28h        ; space for 4 arguments + 16byte aligned stack
   xor r9d, r9d        ; 4. argument: r9d = uType = 0
   lea r8, [caption]   ; 3. argument: r8  = caption
   lea rdx, [text]     ; 2. argument: edx = window text
   xor rcx, rcx        ; 1. argument: rcx = hWnd = NULL
   call MessageBoxA
   xor ecx, ecx        ; ecx = exit code
   call ExitProcess
main endp

   end


Then I made a batch file to build and link it to get the program working:
;Test2.asm is the assembler file I used
;I needed to set the path to c:\masm64\bin because this is where ml64 and link is
;The "/c" ml64 switch will only asseble. No linking is done
;look at all those linker switches. I even had to specify the directory for lib

path = c:\masm64\bin
ml64 /c test2.asm                     
link /entry:main /subsystem:windows /machine:x64 /libpath:c:\masm64\lib test2.obj 

qWord

your live will much easier when using jwasm instead of ml64.exe  :U
FPU in a trice: SmplMath
It's that simple!

Sarel

I tried to use jwlink but could not get it to work. E3033 directive error near 'tried too many switches'. I"m just not getting anything to work maybe I am not typing them correctly. jwlink -windows or -form::=windows or .....
Link from masm64 did work with the object file jwasm created. Only because I got the switches right with link.
At this stage the amount of typing to get the file assembled and linked is pretty much the same between jwasm and masm64.

qWord

assembling an linking is trivial - I were referring to assemblers capabilities :bg
FPU in a trice: SmplMath
It's that simple!

donkey

Quote from: Sarel on March 21, 2011, 05:41:15 PM
I tried to use jwlink but could not get it to work. E3033 directive error near 'tried too many switches'. I"m just not getting anything to work maybe I am not typing them correctly. jwlink -windows or -form::=windows or .....
Link from masm64 did work with the object file jwasm created. Only because I got the switches right with link.
At this stage the amount of typing to get the file assembled and linked is pretty much the same between jwasm and masm64.

Welcome to the club, I tried to get ML64 to work for a simple project and its so badly crippled that its next to useless, I tried JWASM and as all the MASM clones it involved too many downloads of libs etc... that I decided it wasn't worth the effort. I'll stick to GoAsm, a single assembler,RC compiler and linker for x86 or x64 and a single set of header files and no import libraries at all.

http://www.masm32.com/board/index.php?topic=16269.0
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Rockoon

GoAsm is indeed nice, but its macros are a bit limited if you need that sort of thing. I'm one of those 1 macro = 1 or less opcodes kind of guys, so it doesnt bother me.

EasyCode is also a nice IDE for it.
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.

taz

here it comes: the cli-version ;)



---------------------------------------------------------------------------------------

includelib ***\kernel32.lib ; use lib comes with sdk/wdk

extrn __imp_GetStdHandle:proc
extrn __imp_WriteFile:proc



.CODE

main PROC
   mov rax, 00646c726f572034h   
   push rax
   mov rax, 3678206f6c6c6548h
   push rax
   mov rbx, rsp   
   sub rsp, 8
   mov rdi, rsp

   sub rsp, 020h
   mov rcx, -11        ; STD_OUTPUT
   call qword ptr __imp_GetStdHandle
   mov rcx, rax

        mov r9, rdi
   mov r8d, 16
   
   mov rdx, rbx
   call qword ptr __imp_WriteFile
   add rsp, 38h
   ret
main ENDP

END

---------------------------------------------------------------------------------------


to build use following (without brackets):

-> ml64 [filename].asm /link /subsystem:console /entry:main

qWord

congratulations and welcome taz  :U
However, as I've allready said, using japhets jWasm (and WinInc) makes live much easier  :8)
FPU in a trice: SmplMath
It's that simple!