NASM-64 is a possibility, where other people in this group can likely
provide links.
if built right, GAS supports 64 bit code (on Linux x86-64, this is the
default).
I think also YASM has x86-64 support.
...
there are many others as well.
in my case, I wrote my own assembler for my uses (not standalone, but
possibly interesting if one wants an assembler mostly intended for JIT,
where I use a more or less NASM-like syntax).
********************************************************
ml64.exe can be found in many of Microsoft's SDKs.
C:\Asm\MASM\hello>type hello.asm
; File: hello.asm
; Public domain 2008 James Van Buskirk
EXTRN GetStdHandle: PROC
EXTRN WriteFile: PROC
EXTRN ExitProcess: PROC
STD_OUTPUT_HANDLE EQU -11
nNumberOfBytesToWrite EQU Buffer_End - Buffer
TEXT SEGMENT PARA READ EXECUTE "CODE"
PUBLIC start
start:
sub rsp, 40
mov rcx, STD_OUTPUT_HANDLE
call GetStdHandle
mov rcx, rax
mov rdx, OFFSET Buffer
mov r8d, nNumberOfBytesToWrite
mov r9, OFFSET NumberOfBytesWritten
xor eax, eax
mov [rsp+32], rax
call WriteFile
xor ecx, ecx
call ExitProcess
TEXT ENDS
XDATA SEGMENT PARA READ WRITE "DATA"
Buffer db "Hello, world!", 0dh, 0ah
Buffer_End:
ALIGN 4
NumberOfBytesWritten dd ?
XDATA ENDS
END
C:\Asm\MASM\hello>ml64 -c hello.asm
Microsoft (R) Macro Assembler (AMD64) Version 8.00.40310.39
Copyright (C) Microsoft Corporation. All rights reserved.
Assembling: hello.asm
C:\Asm\MASM\hello>link hello.obj /subsystem:console /defaultlib:kernel32.lib
/en
try:start
Microsoft (R) Incremental Linker Version 8.00.40310.39
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Asm\MASM\hello>hello
Hello, world!
********************************************************
YASM http://www.tortall.net/projects/yasm/
C:\Asm\YASM\hello>type hello.asm
extern GetStdHandle
extern WriteFile
extern ExitProcess
[SECTION .data]
align 32
NumberOfBytesWritten:
dd 0
Buffer:
db 'Hello, world!', 0dh, 0ah
nNumberOfBytesToWrite EQU $-Buffer
[SECTION .text]
global _MAIN__
_MAIN__:
sub rsp, 40
mov ecx, -11
call GetStdHandle
mov rcx, rax
mov rdx, Buffer
mov r8d, nNumberOfBytesToWrite
mov r9, NumberOfBytesWritten
xor eax, eax
mov [rsp+32], rax
call WriteFile
xor ecx, ecx
call ExitProcess
C:\Asm\YASM\hello>yasm-0.7.1-win64 -f x64 hello.asm
C:\Asm\YASM\hello>link hello.obj /subsystem:console /entry:_MAIN__
/defaultlib:k
ernel32
Microsoft (R) Incremental Linker Version 8.00.40310.39
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Asm\YASM\hello>hello
Hello, world!
********************************************************
NASM http://nasm.sourceforge.net/
C:\Asm\NASM\hello>type hello.asm
extern GetStdHandle
extern WriteFile
extern ExitProcess
[SECTION .data]
align 32
nNumberOfBytesWritten:
dd 0
Buffer:
db 'Hello, world!', 0dh, 0ah
nNumberOfBytesToWrite EQU $-Buffer
[SECTION .text]
global _MAIN__
_MAIN__:
sub rsp, 40
mov ecx, -11
call GetStdHandle
mov rcx, rax
mov rdx, Buffer
mov r8d, nNumberOfBytesToWrite
mov r9, nNumberOfBytesWritten
xor eax, eax
mov [rsp+32], rax
call WriteFile
xor ecx, ecx
call ExitProcess
C:\Asm\NASM\hello>nasm -f win64 hello.asm
C:\Asm\NASM\hello>link hello.obj /subsystem:console /entry:_MAIN__
/defaultlib:k
ernel32.lib
Microsoft (R) Incremental Linker Version 8.00.40310.39
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Asm\NASM\hello>hello
Hello, world!
********************************************************
GoAsm http://www.jorgon.freeserve.co.uk/
C:\Asm\GoAsm\hello>type hello.asm
DATA SECTION
ALIGN 16
nNumberOfBytesWritten DD 0
Buffer DB 'Hello, world!', 0DH, 0AH
Buffer_end:
nNumberOfBytesToWrite EQU Buffer_end-Buffer
CODE SECTION
START:
SUB rsp, 40
MOV ecx, -11
CALL GetStdHandle
MOV rcx, rax
MOV rdx, OFFSET Buffer
MOV r8d, nNumberOfBytesToWrite
MOV r9, OFFSET nNumberOfBytesWritten
XOR eax, eax
MOV [rsp+32], rax
CALL WriteFile
XOR ecx, ecx
CALL ExitProcess
C:\Asm\GoAsm\hello>GoAsm /x64 hello.asm
GoAsm.Exe Version 0.56.4d - Copyright Jeremy Gordon 2001/8 - J...@JGnet.co.uk
Output file: hello.obj
C:\Asm\GoAsm\hello>golink /console hello.obj kernel32.dll
GoLink.Exe Version 0.26.9d - Copyright Jeremy Gordon 2002/8-...@JGnet.co.uk
Output file: hello.exe
Format: X64 size: 2,048 bytes
C:\Asm\GoAsm\hello>hello
Hello, world!
********************************************************
POASM http://www.smorgasbordet.com/pellesc/
C:\Asm\POASM\hello>type hello.asm
; File: hello.asm
; Public domain 2008 James Van Buskirk
; Assemble, link, and run sequence:
; POASM /AAMD64 hello
; polink /subsystem:CONSOLE /defaultlib:kernel32.lib hello.obj
; hello
.MODEL Flat,FASTCALL
;.CORE ; Not clear why this doesn't work
STD_OUTPUT_HANDLE EQU -11
nNumberOfBytesToWrite EQU Buffer_End - Buffer
.text SEGMENT PARA FLAT READ EXECUTE "CODE"
start:
sub rsp, 40
mov rcx, STD_OUTPUT_HANDLE
call GetStdHandle
mov rcx, rax
mov rdx, OFFSET Buffer
mov r8d, nNumberOfBytesToWrite
mov r9, OFFSET NumberOfBytesWritten
xor eax, eax
mov [rsp+32], rax
call WriteFile
xor ecx, ecx
call ExitProcess
.text ENDS
.xdata SEGMENT PARA FLAT READ WRITE "DATA"
Buffer db "Hello, world!", 0dh, 0ah
Buffer_End:
ALIGN 4
NumberOfBytesWritten dd ?
.xdata ENDS
END start
C:\Asm\POASM\hello>POASM /AAMD64 hello
C:\Asm\POASM\hello>polink /subsystem:CONSOLE /defaultlib:kernel32.lib
hello.obj
C:\Asm\POASM\hello>hello
Hello, world!
********************************************************
GAS can be found many places, e.g.
http://sourceforge.net/projects/mingw-w64/
http://www.equation.com
C:\Asm\GAS\hello>type hello.s
.data
.align 32
nNumberOfBytesWritten:
.long 0
Buffer:
.ascii "Hello, world!\n"
# nNumberOfBytesToWrite = 15
.ascii "\0"
.text
.globl _MAIN__
_MAIN__:
subq $40, %rsp
movl $-11, %ecx
call _GetStdHandle
movq %rax, %rcx
leaq Buffer(%rip), %rdx
# movl nNumberOfBytesToWrite, %r8d
movl $15, %r8d
leaq nNumberOfBytesWritten(%rip), %r9
xorl %eax, %eax
movq %rax, 32(%rsp)
call _WriteFile
xorl %ecx, %ecx
call _ExitProcess
C:\Asm\GAS\hello>as hello.s -ohello.o
C:\Asm\GAS\hello>ld hello.o -lkernel32 -o hello.exe
C:\Asm\GAS\hello>hello
Hello, world!
********************************************************
FASM http://flatassembler.net/
C:\Asm\FASM\hello>type hello.asm
format MS64 coff
extrn GetStdHandle
extrn ExitProcess
extrn WriteFile
STD_OUTPUT_HANDLE = -11
section 'CODE' code readable executable align 16
align 16
public _main
_main:
sub rsp, 40
mov ecx, STD_OUTPUT_HANDLE
call GetStdHandle
mov rcx, rax
mov rdx, Buffer
mov r8d, nNumberOfBytesToWrite
mov r9, lpNumberOfCharsWritten
mov qword[rsp+32], 0
call WriteFile
xor ecx, ecx
call ExitProcess
section 'DATA' data readable writeable align 16
Buffer db 'Hello, world!', 0dh, 0ah
nNumberOfBytesToWrite = $-Buffer
align 4
lpNumberOfCharsWritten dd ?
C:\Asm\FASM\hello>fasm hello.asm
flat assembler version 1.67.18 (1276893 kilobytes memory)
3 passes, 381 bytes.
C:\Asm\FASM\hello>link hello.obj /entry:_main /subsystem:console
/defaultlib:ker
nel32.lib
Microsoft (R) Incremental Linker Version 8.00.40310.39
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Asm\FASM\hello>hello
Hello, world!
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
<<snipped rare 64-bit examples>>
Could I talk you into doing a few more of these? Like, for instance,
for each assembler, demonstrate args processing; then another set for
stdin; etc..
I'm thinking that we need to get this type of material into the ALA/
CLAX FAQ, up on a wiki somewhere, and even onto linuxassembly.org and
such.
Nathan.
-hpa
> On Jun 2, 7:56 pm, "James Van Buskirk" <not_va...@comcast.net> wrote:
> <<snipped rare 64-bit examples>>
> Could I talk you into doing a few more of these? Like, for instance,
> for each assembler, demonstrate args processing; then another set for
> stdin; etc..
I only posted the 7 examples because I just recently found out about
POASM having been added to the nuclear club. It took so much effort
because I downloaded the newest builds of most of the assemblers in
question and the syntax is subtly different in each one. Perhaps you
could start with an example or two in your favorite assembler. It
would also make more concrete what you are asking for: does args
processing mean command-line arguments (doable) or PROC+args (not
feasible in some assemblers, AFAIK)? For stdin, do you mean to
invoke GetStdHandle with rcx = -10, or something else? Perhaps a
set of advocates, one per assembler, can be found to get a standard
set of examples translated. In particular I found as.exe and
especially linking with ld.exe difficult. I think you really need a
good linker script to make it work smoothly in that case and I don't
have a clue about how to get started with that.
> I'm thinking that we need to get this type of material into the ALA/
> CLAX FAQ, up on a wiki somewhere, and even onto linuxassembly.org and
> such.
Of course you will need a set of Linux advocates. Several of the
assemblers I wrote examples for also work in that class of OS.
How about OS-X? My post was intended to be an extension of
http://www.codegurus.be/codegurus/Programming/assembler&win64_en.htm
and to generate interest in x86-64 assembly language coding. If you
would like to drum up further interest, I only consider that to be
a good thing.
P.S. I was at Office Depot today and started playing with one of the
computers on display. I opened Task Manager, switched to the
Processes tab: some of the Image Names were marked "*32"! x64 has
finally appeared at the retail level!