News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Hello World in ASM

Started by runtimeTerror, February 02, 2005, 12:09:37 AM

Previous topic - Next topic

runtimeTerror

Hi, just wondering, as with most languages, the first thing you learn is ow to write out "Hello World". I was wondering
if I could be pointed to some examples on this forum.

Just wanted to keep the first question an easy one.

Cheers, runtime.

P1

Welcome runtimeTerror,    :U

You will find some the best people in the world, come here to get answers, as well as give them.

If you like getting and giving help in Assembler, this is the place for you!!  :clap:

Look forward to you participating with us.   

Start with Downloading MASM32 package and start going through the helps, examples and tutorials there.

This will start you Quick!

Regards,  P1  :8)

white scorpion

well everyone would point you to iczelion's tutorial which you can find here. This is the best tutorial around for masm so i would say give it a try :)

as for a simple hello world:


.386
.model small,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.DATA
AppName  db  "White Scorpion",0
Hello         db  "Hello World!",0

.CODE

start:

invoke MessageBox,NULL,addr Hello,addr AppName,MB_OK

invoke ExitProcess,0

end start



this code calls a messagebox as a simple hello world program.

Nilrem


.386
.model small,stdcall
option casemap:none

include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
include \masm32\macros\macrso.asm

.DATA
Hello         db  "Hello World!",0

.CODE

start:

Routine Proc
   lpstring[128]:DWORD; For user input, see macros.asm

   invoke StdOut, ADDR Hello; Print the message to the screen
   mov lpstring, input (); Press enter and it quits.
   ret
endp



end start

runtimeTerror

Thanks guys! Appreciate the help.

hutch--

hmmmmm,

How about simpler code again using macros.


    cls
    print "Hello World"

    exit


This is why MASM32 has a macro system so the hack stuff is easy to do and make learning assembler a lot simpler.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

tenkey

Otherwise, if you wanted to avoid MASM32 macros, it would look something like this...


; This works a lot better if it's created as a console application
;   (linker option /subsystem:console)

.386
.model small,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.DATA
Hello         db  "Hello World!",13,10
Hello_length  equ $-Hello

BytesWritten  dd 0

.CODE

start:

invoke GetStdHandle,STD_OUTPUT_HANDLE
invoke WriteFile,eax,ADDR Hello,Hello_length,ADDR BytesWritten,NULL

invoke ExitProcess,0

end start
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

James Ladd

Personally I like "tenkey"'s example.