flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > Hello world on x64

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Andy



Joined: 17 Oct 2011
Posts: 26
Hello world on x64
How should I compile a hello world program to can run it on x64 machine?

For example, with this code:

Code:
org 100h
mov dxmsg
mov ah9
int 21h

msg db "Hello world $"  



compiling in that way (it works well without errors)

Code:
fasm hello.asm hello.exe



I got this message
Image

How is the proper way to compile or run this program?
Post 27 Feb 2012, 13:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 12218
Location: Third door on the left. Please knock before entering. Thanks.
Windows 64-bit does not support the DOS VM (NTVDM). You can't run any DOS program natively. You can either use an external VM (like DosBox) or write some Windows native 32-bit or 64-bit code.
Post 27 Feb 2012, 14:02
View user's profile Send private message Visit poster's website Reply with quote
Coty



Joined: 17 May 2010
Posts: 505
Location: ␀
Hello! Windows 64bit does not, in anyway support 16bit programs, this could only be run properly on windows XP 32bit.

To run the program on x64 you can do one of 3 things.

1) Find different code that uses 32bit or 64bit.

2) Download a DOS emulator like DOSBOX, with DOSBOX you can drag and drop your 16bit program onto the DOSBOX.EXE and it will emulate it wonderfully!

3) You can downgrade to windows XP 32bit, but I do not sugjest this on a 64bit machine as 64bit OS runs faster on 64bit machines.

Get DOSBOX here: http://www.dosbox.com/


You should take note, that unlike programming languages like C++, assembly can not simply have a few flags changed to run in x64, you have to write code that will run in x64. This is why people call assembly "un-portable", because you must re-write the code. However, imho re-writing the code is better anyway since you can take full advantage of the machine properly.

_________________
http://codercat.info/
Post 27 Feb 2012, 14:03
View user's profile Send private message Send e-mail Visit poster's website AIM Address Reply with quote
majidkamali1370



Joined: 31 Oct 2010
Posts: 50
Location: Iran
use64 does not work here? Question
Post 27 Feb 2012, 18:23
View user's profile Send private message Send e-mail Yahoo Messenger ICQ Number Reply with quote
Coty



Joined: 17 May 2010
Posts: 505
Location: ␀
No! For one there is no header on a DOS program file! MS windows uses an ELF(?) like header at the beginning of its code that tells windows many things about the program. DOS files are basically RAW binary files. Another thing is, windows does not have the OLD DOS API! Thus, Windows has no idea what int 21h is!

Even windows XP 32bit has no idea what int 21h is, however, if the program is names *.COM, WinXP will launch a built in emulator that for some reason was removed in all 64bit OSes... and any OS newer than windows vista (however 32bit windows vista and windows 7 support text mode only emulation of 16bit programs, and will work so long as it doesn't go into VGA graffics mode or write to screen without using INTS.

_________________
http://codercat.info/


Last edited by Coty on 28 Feb 2012, 01:47; edited 1 time in total
Post 28 Feb 2012, 01:42
View user's profile Send private message Send e-mail Visit poster's website AIM Address Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 12218
Location: Third door on the left. Please knock before entering. Thanks.

Coty wrote:
MS windows uses an ELF(?) like header at the beginning of its code that tells windows many things about the program.

It is a PE header. ELF is for Linux/Unix/and some others
Post 28 Feb 2012, 01:46
View user's profile Send private message Visit poster's website Reply with quote
Andy



Joined: 17 Oct 2011
Posts: 26
Okey. And from where I should start learning about programming FASM on x64 machines? A very basically example would be great. Thanks!
Post 28 Feb 2012, 08:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 12218
Location: Third door on the left. Please knock before entering. Thanks.

Andy wrote:
Okey. And from where I should start learning about programming FASM on x64 machines? A very basically example would be great. Thanks!

Download the Windows version of fasm and in the examples folder is this:

Code:

; Example of 64-bit PE program

format PE64 GUI
entry start

section '.text' code readable executable

  start:
      sub     rsp,8*5         ; reserve stack for API use and make stack dqword aligned

       mov     r9d,0
       lea     r8,[_caption]
       lea     rdx,[_message]
      mov     rcx,0
       call    [MessageBoxA]

   mov     ecx,eax
     call    [ExitProcess]

section '.data' data readable writeable

  _caption db 'Win64 assembly program',0
  _message db 'Hello World!',0

section '.idata' import data readable writeable

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,RVA user_name,RVA user_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dq RVA _ExitProcess
    dq 0
  user_table:
    MessageBoxA dq RVA _MessageBoxA
    dq 0

  kernel_name db 'KERNEL32.DLL',0
  user_name db 'USER32.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _MessageBoxA dw 0
    db 'MessageBoxA',0

Post 28 Feb 2012, 09:09
View user's profile Send private message Visit poster's website Reply with quote
Andy



Joined: 17 Oct 2011
Posts: 26
Thank you, it works. I just have to study a little section .idata. All things there looks so complicated.

LE:
I made it work in this way:

Code:
include "win64ax.inc"

.data
Caption db 'Win64 assembly program',0
Message db 'Hello World!',0

.code
start:
xor r9d,r9d
lea r8,[Caption]
lea rdx,[Message]
xor rcx,rcx
call [MessageBox]
mov ecx,eax
invoke ExitProcess,0
.end start 



My question now is: if I include win64ax what kind of APIs can I call? I am able to call any function from kernel32.dll or shell32.dll?
Post 28 Feb 2012, 09:35
View user's profile Send private message Reply with quote
questlima



Joined: 27 Aug 2014
Posts: 37
i think you can call all the functions not sure i am new to FASM

kernel32.inc
user32.inc
gdi32.inc
advapi32.inc
comctl32.inc
comdlg32.inc
shell32.inc
wsock32.inc

http://code.google.com/p/vyne-compiler/source/browse/VyneCompiler/INCLUDE/WIN64AX.INC
Post 27 Aug 2014, 14:40
View user's profile Send private message Reply with quote
flatH



Joined: 30 Sep 2014
Posts: 11
How can i write a text to console?
Post 30 Sep 2014, 06:09
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1083
Location: United States

flatH wrote:
How can i write a text to console?




Code:

code section:
stdcall [GetStdHandle],STD_OUTPUT_HANDLE
stdcall [WriteFile],eax,message,message.length,esp,0

data section:
message db "Hello World!",13,10
.length = ($-message)



_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 30 Sep 2014, 07:37
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
flatH



Joined: 30 Sep 2014
Posts: 11
I get the message


Quote:
Error: illegal instruction.
Display: /
Instruction: code section:

Post 30 Sep 2014, 07:42
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2650
Location: 0x77760000
Don't copy "code section" and "data section".
That was there to tell you where you need to put the code.
Post 30 Sep 2014, 12:51
View user's profile Send private message Visit poster's website Reply with quote
flatH



Joined: 30 Sep 2014
Posts: 11
I get now:


Quote:

Error: illegal instruction.
instruction: stdcall[GetStdHandle],STD_OUTPUT_HANDLE

Post 30 Sep 2014, 13:04
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2650
Location: 0x77760000

Code:

invoke GetStdHandleSTD_OUTPUT_HANDLE




or

Code:

push STD_OUTPUT_HANDLE
call   [GetStdHandle]


Post 30 Sep 2014, 20:10
View user's profile Send private message Visit poster's website Reply with quote
flatH



Joined: 30 Sep 2014
Posts: 11
Sorry to ask again Embarassed

Do you mean like this?


Code:

invoke GetStdHandleSTD_OUTPUT_HANDLE

stdcall [WriteFile],eax,message,message.length,esp,0

message db "Hello World!",13,10
.length = ($-message)




I then get:


Quote:

Error: illegal instruction
Instruction: invoke GetStdHandle,STD_OUTPUT_HANDLE



if i mussonderstood your answer, i am sorry. Assembler is completely different to me then any other language i learned so far.
Post 01 Oct 2014, 05:33
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1083
Location: United States
Start by copying an existing sample and modifying it.
Post 01 Oct 2014, 07:50
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
flatH



Joined: 30 Sep 2014
Posts: 11
It's kinda hard to find a sample for x64 and console (no message box)...
Post 02 Oct 2014, 05:42
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1083
Location: United States
You were already given a pointer to samples under FASM\SAMPLES\WIN64 on another thread you started.
Post 02 Oct 2014, 08:34
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2013, Tomasz Grysztar.