There is an assembly code written for Windows API, how to compile it on Linux and run with Wine












1















There is an example code in this introduction, like below:



; Sample x64 Assembly Program
; Chris Lomont 2009 www.lomont.org
extrn ExitProcess: PROC ; external functions in system libraries
extrn MessageBoxA: PROC
.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 MessageBoxA ; call MessageBox API function
mov ecx, eax ; uExitCode = MessageBox(...)
call ExitProcess
Start ENDP
End


The above code is inside hello.asm and on Windows, it can be compiled with:



ml64 hello.asm /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Start


I don't have access to Windows and MASM, since I'm on Linux and work with NASM. I think if I compile the code on Linux, I would be able to run it with Wine. But yet, I couldn't figure out how to compile it with NASM on Linux and also I couln't figure out what are the NASM options which are equivalent to the MASM ones. Can anybody help me?










share|improve this question




















  • 2





    You should be able to find a nasm syntax hello world.

    – Jester
    Mar 13 '18 at 14:52











  • I recommend reading some other thing as assembler tutorial. BTW, see also Assembler HowTo and read syscalls(2)

    – Basile Starynkevitch
    Mar 13 '18 at 14:52













  • @BasileStarynkevitch I bookmarked those links. I'm going to study them. Thanks.

    – user3405291
    Mar 13 '18 at 15:08
















1















There is an example code in this introduction, like below:



; Sample x64 Assembly Program
; Chris Lomont 2009 www.lomont.org
extrn ExitProcess: PROC ; external functions in system libraries
extrn MessageBoxA: PROC
.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 MessageBoxA ; call MessageBox API function
mov ecx, eax ; uExitCode = MessageBox(...)
call ExitProcess
Start ENDP
End


The above code is inside hello.asm and on Windows, it can be compiled with:



ml64 hello.asm /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Start


I don't have access to Windows and MASM, since I'm on Linux and work with NASM. I think if I compile the code on Linux, I would be able to run it with Wine. But yet, I couldn't figure out how to compile it with NASM on Linux and also I couln't figure out what are the NASM options which are equivalent to the MASM ones. Can anybody help me?










share|improve this question




















  • 2





    You should be able to find a nasm syntax hello world.

    – Jester
    Mar 13 '18 at 14:52











  • I recommend reading some other thing as assembler tutorial. BTW, see also Assembler HowTo and read syscalls(2)

    – Basile Starynkevitch
    Mar 13 '18 at 14:52













  • @BasileStarynkevitch I bookmarked those links. I'm going to study them. Thanks.

    – user3405291
    Mar 13 '18 at 15:08














1












1








1








There is an example code in this introduction, like below:



; Sample x64 Assembly Program
; Chris Lomont 2009 www.lomont.org
extrn ExitProcess: PROC ; external functions in system libraries
extrn MessageBoxA: PROC
.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 MessageBoxA ; call MessageBox API function
mov ecx, eax ; uExitCode = MessageBox(...)
call ExitProcess
Start ENDP
End


The above code is inside hello.asm and on Windows, it can be compiled with:



ml64 hello.asm /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Start


I don't have access to Windows and MASM, since I'm on Linux and work with NASM. I think if I compile the code on Linux, I would be able to run it with Wine. But yet, I couldn't figure out how to compile it with NASM on Linux and also I couln't figure out what are the NASM options which are equivalent to the MASM ones. Can anybody help me?










share|improve this question
















There is an example code in this introduction, like below:



; Sample x64 Assembly Program
; Chris Lomont 2009 www.lomont.org
extrn ExitProcess: PROC ; external functions in system libraries
extrn MessageBoxA: PROC
.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 MessageBoxA ; call MessageBox API function
mov ecx, eax ; uExitCode = MessageBox(...)
call ExitProcess
Start ENDP
End


The above code is inside hello.asm and on Windows, it can be compiled with:



ml64 hello.asm /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Start


I don't have access to Windows and MASM, since I'm on Linux and work with NASM. I think if I compile the code on Linux, I would be able to run it with Wine. But yet, I couldn't figure out how to compile it with NASM on Linux and also I couln't figure out what are the NASM options which are equivalent to the MASM ones. Can anybody help me?







assembly 64bit nasm masm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 13 '18 at 14:52







user3405291

















asked Mar 13 '18 at 14:50









user3405291user3405291

1,91412141




1,91412141








  • 2





    You should be able to find a nasm syntax hello world.

    – Jester
    Mar 13 '18 at 14:52











  • I recommend reading some other thing as assembler tutorial. BTW, see also Assembler HowTo and read syscalls(2)

    – Basile Starynkevitch
    Mar 13 '18 at 14:52













  • @BasileStarynkevitch I bookmarked those links. I'm going to study them. Thanks.

    – user3405291
    Mar 13 '18 at 15:08














  • 2





    You should be able to find a nasm syntax hello world.

    – Jester
    Mar 13 '18 at 14:52











  • I recommend reading some other thing as assembler tutorial. BTW, see also Assembler HowTo and read syscalls(2)

    – Basile Starynkevitch
    Mar 13 '18 at 14:52













  • @BasileStarynkevitch I bookmarked those links. I'm going to study them. Thanks.

    – user3405291
    Mar 13 '18 at 15:08








2




2





You should be able to find a nasm syntax hello world.

– Jester
Mar 13 '18 at 14:52





You should be able to find a nasm syntax hello world.

– Jester
Mar 13 '18 at 14:52













I recommend reading some other thing as assembler tutorial. BTW, see also Assembler HowTo and read syscalls(2)

– Basile Starynkevitch
Mar 13 '18 at 14:52







I recommend reading some other thing as assembler tutorial. BTW, see also Assembler HowTo and read syscalls(2)

– Basile Starynkevitch
Mar 13 '18 at 14:52















@BasileStarynkevitch I bookmarked those links. I'm going to study them. Thanks.

– user3405291
Mar 13 '18 at 15:08





@BasileStarynkevitch I bookmarked those links. I'm going to study them. Thanks.

– user3405291
Mar 13 '18 at 15:08












2 Answers
2






active

oldest

votes


















5














You should have been able to find a nasm syntax hello world. Anyway, here is a quick transcription:



extern ExitProcess
extern MessageBoxA
section .data
caption db '64-bit hello!', 0
message db 'Hello World!', 0
section .text
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 MessageBoxA ; call MessageBox API function
mov ecx, eax ; uExitCode = MessageBox(...)
call ExitProcess


Assemble using nasm -f win64 hello.asm. You will also need a linker, I used the mingw port as ld hello.obj -lkernel32 -luser32 (let me emphasize this is not the native ld)






share|improve this answer
























  • Related: a 32-bit NASM hello world with a Linux sys_write system call. It prints to its stdout (i.e. on a terminal) instead of calling a GUI message box function, using native Linux system calls, no WINE needed. It's heavily commented and with separate paragraphs describing how it works. I wrote it for SO docs, then ported it to an answer where it fits when SO docs shut down.

    – Peter Cordes
    Mar 14 '18 at 3:54





















4














Although package names vary from Linux distro to distro, you can do what you are suggesting by installing (or building from source) a mingw-w64 tool chain and the program JWASM. JWASM is a an assembler that is mostly compatible with MASM.



On Debian based distros (including Ubuntu) you should be able to install the prerequisites with:



apt-get install mingw-w64-x86-64-dev binutils-mingw-w64-x86-64 jwasm


With Ubuntu based systems you'll need to prepend the command above with sudo.



You should then be able to assemble and link using something like:



jwasm -win64 hello.asm
x86_64-w64-mingw32-ld hello.o -lkernel32 -luser32 -o hello.exe


The executable should be runnable using wine64






share|improve this answer





















  • 1





    I wish I could accept more than one answer. Thanks, your answer was very helpful.

    – user3405291
    Mar 13 '18 at 15:59












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49259228%2fthere-is-an-assembly-code-written-for-windows-api-how-to-compile-it-on-linux-an%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














You should have been able to find a nasm syntax hello world. Anyway, here is a quick transcription:



extern ExitProcess
extern MessageBoxA
section .data
caption db '64-bit hello!', 0
message db 'Hello World!', 0
section .text
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 MessageBoxA ; call MessageBox API function
mov ecx, eax ; uExitCode = MessageBox(...)
call ExitProcess


Assemble using nasm -f win64 hello.asm. You will also need a linker, I used the mingw port as ld hello.obj -lkernel32 -luser32 (let me emphasize this is not the native ld)






share|improve this answer
























  • Related: a 32-bit NASM hello world with a Linux sys_write system call. It prints to its stdout (i.e. on a terminal) instead of calling a GUI message box function, using native Linux system calls, no WINE needed. It's heavily commented and with separate paragraphs describing how it works. I wrote it for SO docs, then ported it to an answer where it fits when SO docs shut down.

    – Peter Cordes
    Mar 14 '18 at 3:54


















5














You should have been able to find a nasm syntax hello world. Anyway, here is a quick transcription:



extern ExitProcess
extern MessageBoxA
section .data
caption db '64-bit hello!', 0
message db 'Hello World!', 0
section .text
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 MessageBoxA ; call MessageBox API function
mov ecx, eax ; uExitCode = MessageBox(...)
call ExitProcess


Assemble using nasm -f win64 hello.asm. You will also need a linker, I used the mingw port as ld hello.obj -lkernel32 -luser32 (let me emphasize this is not the native ld)






share|improve this answer
























  • Related: a 32-bit NASM hello world with a Linux sys_write system call. It prints to its stdout (i.e. on a terminal) instead of calling a GUI message box function, using native Linux system calls, no WINE needed. It's heavily commented and with separate paragraphs describing how it works. I wrote it for SO docs, then ported it to an answer where it fits when SO docs shut down.

    – Peter Cordes
    Mar 14 '18 at 3:54
















5












5








5







You should have been able to find a nasm syntax hello world. Anyway, here is a quick transcription:



extern ExitProcess
extern MessageBoxA
section .data
caption db '64-bit hello!', 0
message db 'Hello World!', 0
section .text
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 MessageBoxA ; call MessageBox API function
mov ecx, eax ; uExitCode = MessageBox(...)
call ExitProcess


Assemble using nasm -f win64 hello.asm. You will also need a linker, I used the mingw port as ld hello.obj -lkernel32 -luser32 (let me emphasize this is not the native ld)






share|improve this answer













You should have been able to find a nasm syntax hello world. Anyway, here is a quick transcription:



extern ExitProcess
extern MessageBoxA
section .data
caption db '64-bit hello!', 0
message db 'Hello World!', 0
section .text
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 MessageBoxA ; call MessageBox API function
mov ecx, eax ; uExitCode = MessageBox(...)
call ExitProcess


Assemble using nasm -f win64 hello.asm. You will also need a linker, I used the mingw port as ld hello.obj -lkernel32 -luser32 (let me emphasize this is not the native ld)







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 13 '18 at 14:56









JesterJester

46.9k34784




46.9k34784













  • Related: a 32-bit NASM hello world with a Linux sys_write system call. It prints to its stdout (i.e. on a terminal) instead of calling a GUI message box function, using native Linux system calls, no WINE needed. It's heavily commented and with separate paragraphs describing how it works. I wrote it for SO docs, then ported it to an answer where it fits when SO docs shut down.

    – Peter Cordes
    Mar 14 '18 at 3:54





















  • Related: a 32-bit NASM hello world with a Linux sys_write system call. It prints to its stdout (i.e. on a terminal) instead of calling a GUI message box function, using native Linux system calls, no WINE needed. It's heavily commented and with separate paragraphs describing how it works. I wrote it for SO docs, then ported it to an answer where it fits when SO docs shut down.

    – Peter Cordes
    Mar 14 '18 at 3:54



















Related: a 32-bit NASM hello world with a Linux sys_write system call. It prints to its stdout (i.e. on a terminal) instead of calling a GUI message box function, using native Linux system calls, no WINE needed. It's heavily commented and with separate paragraphs describing how it works. I wrote it for SO docs, then ported it to an answer where it fits when SO docs shut down.

– Peter Cordes
Mar 14 '18 at 3:54







Related: a 32-bit NASM hello world with a Linux sys_write system call. It prints to its stdout (i.e. on a terminal) instead of calling a GUI message box function, using native Linux system calls, no WINE needed. It's heavily commented and with separate paragraphs describing how it works. I wrote it for SO docs, then ported it to an answer where it fits when SO docs shut down.

– Peter Cordes
Mar 14 '18 at 3:54















4














Although package names vary from Linux distro to distro, you can do what you are suggesting by installing (or building from source) a mingw-w64 tool chain and the program JWASM. JWASM is a an assembler that is mostly compatible with MASM.



On Debian based distros (including Ubuntu) you should be able to install the prerequisites with:



apt-get install mingw-w64-x86-64-dev binutils-mingw-w64-x86-64 jwasm


With Ubuntu based systems you'll need to prepend the command above with sudo.



You should then be able to assemble and link using something like:



jwasm -win64 hello.asm
x86_64-w64-mingw32-ld hello.o -lkernel32 -luser32 -o hello.exe


The executable should be runnable using wine64






share|improve this answer





















  • 1





    I wish I could accept more than one answer. Thanks, your answer was very helpful.

    – user3405291
    Mar 13 '18 at 15:59
















4














Although package names vary from Linux distro to distro, you can do what you are suggesting by installing (or building from source) a mingw-w64 tool chain and the program JWASM. JWASM is a an assembler that is mostly compatible with MASM.



On Debian based distros (including Ubuntu) you should be able to install the prerequisites with:



apt-get install mingw-w64-x86-64-dev binutils-mingw-w64-x86-64 jwasm


With Ubuntu based systems you'll need to prepend the command above with sudo.



You should then be able to assemble and link using something like:



jwasm -win64 hello.asm
x86_64-w64-mingw32-ld hello.o -lkernel32 -luser32 -o hello.exe


The executable should be runnable using wine64






share|improve this answer





















  • 1





    I wish I could accept more than one answer. Thanks, your answer was very helpful.

    – user3405291
    Mar 13 '18 at 15:59














4












4








4







Although package names vary from Linux distro to distro, you can do what you are suggesting by installing (or building from source) a mingw-w64 tool chain and the program JWASM. JWASM is a an assembler that is mostly compatible with MASM.



On Debian based distros (including Ubuntu) you should be able to install the prerequisites with:



apt-get install mingw-w64-x86-64-dev binutils-mingw-w64-x86-64 jwasm


With Ubuntu based systems you'll need to prepend the command above with sudo.



You should then be able to assemble and link using something like:



jwasm -win64 hello.asm
x86_64-w64-mingw32-ld hello.o -lkernel32 -luser32 -o hello.exe


The executable should be runnable using wine64






share|improve this answer















Although package names vary from Linux distro to distro, you can do what you are suggesting by installing (or building from source) a mingw-w64 tool chain and the program JWASM. JWASM is a an assembler that is mostly compatible with MASM.



On Debian based distros (including Ubuntu) you should be able to install the prerequisites with:



apt-get install mingw-w64-x86-64-dev binutils-mingw-w64-x86-64 jwasm


With Ubuntu based systems you'll need to prepend the command above with sudo.



You should then be able to assemble and link using something like:



jwasm -win64 hello.asm
x86_64-w64-mingw32-ld hello.o -lkernel32 -luser32 -o hello.exe


The executable should be runnable using wine64







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 13 '18 at 16:00

























answered Mar 13 '18 at 15:50









Michael PetchMichael Petch

27.1k557106




27.1k557106








  • 1





    I wish I could accept more than one answer. Thanks, your answer was very helpful.

    – user3405291
    Mar 13 '18 at 15:59














  • 1





    I wish I could accept more than one answer. Thanks, your answer was very helpful.

    – user3405291
    Mar 13 '18 at 15:59








1




1





I wish I could accept more than one answer. Thanks, your answer was very helpful.

– user3405291
Mar 13 '18 at 15:59





I wish I could accept more than one answer. Thanks, your answer was very helpful.

– user3405291
Mar 13 '18 at 15:59


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49259228%2fthere-is-an-assembly-code-written-for-windows-api-how-to-compile-it-on-linux-an%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$