NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: Balsiger on May 19, 2014, 03:35:03 PM
-
Hello,
my english is maybe not very good. So please forgive me.
When I compile a program comes the message, that it is not compatible with 64 bit.
Please tell me, how must I compile a program that it runs on windows 64 bit?
For example a simple program that writes hello world to the console.
Please tell me all I need to know that the program writes hello world.
segment code
start:
mov ax, data
mov ds, ax
mov dx, hello
mov ah, 09h
int 21h
mov al, 0
mov ah, 4Ch
int 21h
segment data
hello: db 'Hello World!', 13, 10, '$'
-
Hello,
my english is maybe not very good. So please forgive me.
I forgive you! ;D
Hi! That code will not work, it looks like it's for x16.
Win64 Hello world using GCC:
1. Install development environment: MinGW-w64: GCC for both x64 & x86 Windows! (http://mingw-w64.sourceforge.net/)
2. Helloworld.asm:
bits 64
section .data
message: db "Hello World!!!",0
section .text
global main
extern printf
main:
sub rsp,0x28
mov rcx,message
call printf
add rsp,0x28
ret
3. Compile: "nasm.exe -f win64 helloworld.asm -o helloworld.obj".
4. Build: "gcc helloworld.obj -o helloworld.exe".
And that's it!
-
Thank you for your very fast answer.
I will try what you told.
And tell you if it worked.
-
Thank you for your very fast answer.
I will try what you told.
And tell you if it worked.
Line[0]: Okey, Cool! I'm waiting... Don't forget to report about how it worked.
Line[1]: Maybe you will need to add gcc and nasm to environment variables, so it can be accessed trough console - cmd. (Well, at least it's more comfortable if they are added to environment variables).
-
That program is written for MS-DOS. You could run it in "dosbox" in Linux. This is the program
in ".COM" format. DOS used "INT 21h", whereas 32 bit Linux uses "INT 80h" and 64 bit uses SYSCALL.
Here's an example of your code that runs under "DOSBOX" within Linux. Haven't tried under Windows.
; Compiled with NASM, trace through with either GRDB.EXE or DEBUG.EXE
; COMPILE CMD: C:\>nasm hello.asm -o hello.com
;============================================================================
;
bits 16 ;16 bit program (DOS)
org 100h ;All .COM files origin
jmp _start ;We jump over data
;
; Data section.
;
msg db 'Hello World!!!',0Ah,0Dh,'$'
;
; Code start.
;
_start:
;
mov ah,09h ;DOS print string call
mov dx,msg ;Point to message
int 21h ;* DOS call
;
;Exit program.
;
mov ah,4ch ;Exit with errorlevel
mov al,00h ; errorlevel=0
int 21h ;* DOS call