flat assembler
Message board for the users of flat assembler.

Index > Windows > Hello world.exe compile error

Author
Thread Post new topic Reply to topic
stack



Joined: 14 Nov 2010
Posts: 6
stack
Please help me to compile my Hello world program. It's ok when output format is .com, but does not work when format is format PE console.

Code:
format PE console  ;ORG 100h - it's ok when output is .com

mov dx,msg
mov ah,9h
int 21h

mov ah,10h
int 16h

int 21h

msg db "Hello World!$"
    


The error is: "value out of range" (line: mov dx,msg). I want to write code without FASM "invoke WriteConsole". Please help me to write the simplest exe proggy.
Post 14 Nov 2010, 09:00
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
stack,

Why do you need PE with 16-bit code which won't work (under regular Windows)?

In protected mode you don't have much choice in user-mode: there are APIs you can use, there are (barely documented) OS services. None of them resemble DOS int 21h or BIOS int 16h (indeed you'll have access violation trying to use those instructions).

You don't want to use WriteConsole()? Use WriteFile() then. Wink
Post 14 Nov 2010, 09:35
View user's profile Send private message Reply with quote
stack



Joined: 14 Nov 2010
Posts: 6
stack
baldr, thanks for reply. I thought that the problem in the syntax only or maybe something with ds register value Smile
Post 14 Nov 2010, 09:47
View user's profile Send private message Reply with quote
stack



Joined: 14 Nov 2010
Posts: 6
stack
Hmm, "format mz" works. At least there is no any compilation error, but the output is: "()&^#(&^@#... Hello World!". How should I modify the source code to set proper output address for 21h interrupt? And I get a NTVDM.exe unstable crash...
Post 14 Nov 2010, 12:24
View user's profile Send private message Reply with quote
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole
I think it complains because dx is too small to hold a 32 bit address. If you use edx instead, the error goes away.

Still, as baldr said, there is other issues. Basically you are using old DOS interrupts that does not work in protected mode.

Are you on Windows, Linux or other system?
Post 14 Nov 2010, 14:13
View user's profile Send private message Reply with quote
stack



Joined: 14 Nov 2010
Posts: 6
stack
I'm on Win7. The following code is work ok except unstable crash of NTVDM.exe on exit.
Code:
format mz
org 100h

mov edx,msg
mov ah,9h
int 21h

mov ah,10h
int 16h

int 21h

msg db "Hello World!$"    


I just wanted to start with basic DOS programs for studying, because there are a lot of tutorials of them.[/code]
Post 14 Nov 2010, 15:25
View user's profile Send private message Reply with quote
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole
The interrupt to exit a com program is 20h I think, not 21h
Post 14 Nov 2010, 16:50
View user's profile Send private message Reply with quote
stack



Joined: 14 Nov 2010
Posts: 6
stack
Oh, yes. I changed interrupt to exit, but the crash of NTVDM.exe still here:
Problem Event Name: APPCRASH
Application Name: ntvdm.exe
Application Version: 6.1.7600.16385
Application Timestamp: 4a5bc158
Fault Module Name: StackHash_2264
Post 14 Nov 2010, 17:16
View user's profile Send private message Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 294
Alphonso
Code:
format mz

;org 100h
push cs
pop  ds

mov dx,msg
mov ah,9h
int 21h

mov ah,0h
int 16h

mov ax,4c00h ;Use AL for error/return code
int 21h

msg db "Hello World!$" 

    
Post 15 Nov 2010, 09:47
View user's profile Send private message Reply with quote
stack



Joined: 14 Nov 2010
Posts: 6
stack
Thanks, Alphonso!
Post 16 Nov 2010, 18:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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 can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.