flat assembler
Message board for the users of flat assembler.

Index > Windows > Hello World my first program

Author
Thread Post new topic Reply to topic
_Rob_



Joined: 15 Dec 2012
Posts: 17
Location: Boston, MA
_Rob_
Hello to all the flat assembler community!

I have a few questions and some code here that I picked up off YouTube. But first I was just curious as to why this code is locking up my console window? Attached is a picture of the error. Also, after I compile the executable is saved as .COM and I was expecting .EXE ??

Code:
; http://www.youtube.com/watch?v=83DZHtjd6QM


ORG 100h        ; 100h is a general purpose place in memory where the program will be loaded
USE16           ; use 16 bit memory

        ; Intel syntax-  ah and dx are registers dx data register
        mov ah, 09      ; 09 is the equivalent dos print string function
        mov dx, msg     ; msg is a variable

        int 21h         ; int is interup it stops everything even at the cpu level to run this
        mov ah, 01      ; 01 is the wait key function of dos
        int 21h
        mov ah, 4ch     ; 4ch returns control to the operating system
        int 21h

        ; define the variable msg db stands for define bites
        msg db 'Hellow World!', 0AH, '$' ; 0AH dos is a line feed and $ is the line terminated char
                                          
    


Description: error message when I try and close this console window.
Filesize: 26.78 KB
Viewed: 927 Time(s)

asm-error-HW.PNG


Post 15 Dec 2012, 17:40
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
It's DOS related problem.
You have to press any key to close the window.
if you want EXE, here it is, but will confuse you I guess.

Code:
format PE CONSOLE 4.0 ;4.0 = WinNT+
include 'win32ax.inc' ;standard include.
.data
message db "Hello, World!",0
sizeof.message = $ - message
wbytes dd ?
.code
start:
invoke WriteFile, STD_OUTPUT_HANDLE, "Hello World!", 12, 0, wbytes
ret
.end start    
Post 15 Dec 2012, 18:09
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
I see in the YouTube video description a link to DOSBOX. That's where you should run the resulting .com file because your code is DOS code that won't run under any modern Windows system (AFAIK).

You may have downloaded the DOS version of FASM. If you want to code Windows applications you should get the Windows version.
You'll find a working "Hello World" code in the "Examples" directory.
Or you can use the console under Windows. There are many examples around here such as in this recent thread.
Post 15 Dec 2012, 18:10
View user's profile Send private message Reply with quote
_Rob_



Joined: 15 Dec 2012
Posts: 17
Location: Boston, MA
_Rob_
Should have included this info in my post, sorry for that. I am using the "fasmw17003" for windows and I am on an older XP operating system 2002 x32.
Post 15 Dec 2012, 18:33
View user's profile Send private message Reply with quote
_Rob_



Joined: 15 Dec 2012
Posts: 17
Location: Boston, MA
_Rob_
Overflowz wrote:
It's DOS related problem.
You have to press any key to close the window.
if you want EXE, here it is, but will confuse you I guess.

Code:
format PE CONSOLE 4.0 ;4.0 = WinNT+
include 'win32ax.inc' ;standard include.
.data
message db "Hello, World!",0
sizeof.message = $ - message
wbytes dd ?
.code
start:
invoke WriteFile, STD_OUTPUT_HANDLE, "Hello World!", 12, 0, wbytes
ret
.end start    


Thanks for the help on how to close the window on the original code. So one example uses DOS, and your version uses C type language?? Can you explain the basic concepts on how this works? I mean I am thinking ASM is for very low level stuff so If I was doing low level would I be using C type syntax?

I am just curious that's all, I am not a very good programmer I just find this stuff very interesting.

Thanks.
Post 15 Dec 2012, 18:50
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
You can always use the more Windows-specific WriteConsole API.

I haven't tested it, but there's an example in the link I posted last time.
You can also check this page.
Post 15 Dec 2012, 19:06
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
_Rob_
Sure. now take a look this code with nice comments.
Code:
format PE CONSOLE 4.0 ;4.0 = we wanna console app and above WinNT systems should run this.
include 'win32ax.inc' ;include file, which includes some additional stuff like macros, equotes, etc..
.data ;this is just macro for "section '.data' data readable writeable
message db "Hello, World!",0 ;this is our message, including null-terminator (but we actually don't need it.)
sizeof.message = $ - message ;$ means current location, whenever we subtract previous value to current location, we get size of string, easy though.
wbytes dd ? ;define DWORD value for WriteFile API. http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747(v=vs.85).aspx
.code ;another macro for "section '.text' code readable executable
start: ;execution will start from here.
invoke WriteFile, STD_OUTPUT_HANDLE, message, sizeof.message, 0, wbytes ;invoke macro which is included in win32a/x.inc it's similar as push wbytes, push 0, push sizeof.message, push message, push STD_OUTPUT_HANDLE, call [WriteFile]
ret ;exit our procedure Smile
.end start ;macro for entry label (at this point, it will be start. tells compiler where execution should begin first, it's an AddressOfEntryPoint.)
    

I'm not good teacher, but I can suggest you if this is your first language, start with C and then move to asm.
P.S It's WinAPI, not C. C API is in msvcrt.dll.
Post 15 Dec 2012, 19:14
View user's profile Send private message Reply with quote
_Rob_



Joined: 15 Dec 2012
Posts: 17
Location: Boston, MA
_Rob_
Well lets see I have taken C for UNIX and VS C++ both intro classes. But since I took these classes just for fun, and I am only a windows user not a programmer by trade; In the end I picked up VB.NET and Its all I use now.

But I am interested in low level stuff and why I joined this forum. I am also interested in the MenuetOS operating system. I think my long range goal is developing some low level stuff. How well that goes well it could end up like my C++ class TOUGH!

Thanks again for the comments and the links!
Post 15 Dec 2012, 20:15
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Assembly teaches you more in terms of computer programming.

The most fundamental thing to learn is data structuring, addressing and access. These have to do with some of the most vital parts of a program's execution, like the STACK and or calling conventions.

One you get a grasp of that, you're good to go.


Last edited by typedef on 16 Dec 2012, 13:21; edited 1 time in total
Post 15 Dec 2012, 20:42
View user's profile Send private message Reply with quote
_Rob_



Joined: 15 Dec 2012
Posts: 17
Location: Boston, MA
_Rob_
typedef wrote:
Assembly teaches you more in terms of computer programming.

The most fundamental thing to learn is data structuring, addressing and access. These have to do with some of the most vital parts of a programs execution, like the STACK and or calling conventions.

One you get a grasp of that, you're good to go.


If you have any links regarding this stuff I would be interested. But I would agree with your point.
Post 16 Dec 2012, 01:40
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
Post 16 Dec 2012, 08:29
View user's profile Send private message Reply with quote
_Rob_



Joined: 15 Dec 2012
Posts: 17
Location: Boston, MA
_Rob_
ManOfSteel wrote:
The documentation has pretty much everything you need.

Start with these:
http://flatassembler.net/docs.php?article=manual
http://flatassembler.net/docs.php?article=win32


Nice, thanks for the links now I know where to start.
Post 16 Dec 2012, 15:19
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.