×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Hello World for MASM 32 !!

Hello World for MASM 32 !!

Hello World for MASM 32 !!

(OP)
Hello,
   I am new to using MASM 32 and I tried the following program in the MASM 32 version 8. The problem is that it assembles and links fine but when I run it Windows does not like it and gives an illegal function call.

.386
.model flat, STDCALL

.data
    message db  "HelloWorld!$"
.code

org 100h

start:

    mov edx, offset message
    mov ah, 09
    int 21h
    mov ax, 4c00h
    int 21h
    
end start

  Isn't the int 21 interrupt available in Windows 98 as in DOS? Well can anyone give me a simple Hello World example for MASM 32.
   Also can't we make console applications in MASM 32??
Please help.

RE: Hello World for MASM 32 !!

Your problem is that you forgot to null-terminate the string.

change the line:
  message db  "HelloWorld!$"
to:
  message db "HelloWorld!",0

...and you should be fine.

--------
It is an honor to recieve an honest reply. (Prov 24:26)

RE: Hello World for MASM 32 !!

(OP)
Well I tried that also but still it doesn't work !!!
   Any more ideas???

RE: Hello World for MASM 32 !!

It's been a long time since I've done ASM programming in dos, but is the interrupt you're looking for 09, or 09h?  You could try that.

--------
It is an honor to recieve an honest reply. (Prov 24:26)

RE: Hello World for MASM 32 !!

(OP)
I tried that as well still the same !!!

RE: Hello World for MASM 32 !!

Bertv is right.
The interrupt will only look at the dx register. Also, in your program you have not set up your data segment.
I have rewritten your program in the generic form, which will assemble on masm,tasm,etc. Read the comments...

; The assume statements are required.
; BUT the DS register MUST still be set
; to the segment address.

assume cs:code,ds:data

code segment

    org 100h       ; for com files
hello:

    mov ax,data    ; set data segment
    mov ds,ax   

; NB: I use lea more than using offsets if I can help it.
    lea dx,message ; message printed
    mov ah,09h
    int 21h

    mov ax,4c00h   ; terminate
    int 21h

code ends


data segment

; The $ is the terminating character in the DOS
; message print interrupt. Zero is used in the
; BIOS interrupt for message print.
    message db  "Hello, World!$"

data ends


end hello

When code is written this way, it looks much nicer.

     Adonai

RE: Hello World for MASM 32 !!

Also, 09 and 09h are the same because 1 to 9 are the same whether in hex or in dec (or oct, accept 09 doesn't exist...). The 'h' becomes important for numbers greater than 9, for example 10 without 'h' is usually 10 decimal, but with 'h' equals 16 decimal, or if octal = 8 decimal, or with a 'b' = 2 decimal.

I always put the 'h' even with numbers below A, but that is just habbit, and hex is much better than dec in assembly.
I think I've said enough, so I'll shut-up now.


RE: Hello World for MASM 32 !!

Ok, I feel like an idiot... I knew that, but I guess I didn't really think Ad, you are quite right... 09 is the same as 09h... wow I feel like a tard

--------
It is an honor to recieve an honest reply. (Prov 24:26)

RE: Hello World for MASM 32 !!

little summary. 1st, judging from ur code, u r trying to assembly a DOS com file. DOS int services ARE AVAILABLE under win9x. the original code itself looks OK, except for u should not set additional segment for data - com files are in ONE 16 bit SEGMENT. u can make a assembler to swallow this but it's misleading (at least for me!).
dont set edx in ur code - it's senseless as, as noted by others, only low 16 bits (DX) are used by the interrupt.
what i'm worring about is model flat. i never have made COM files with a win32 assembler (masm 5.x makes this perfectly) but "flat" is associated for me with flat 32 bit addressing (will appreciate comments from a wiseman :)). and probably the most important thing is what switches/flags are used for compilation/linking? aint u making (with no intention!) a win32 program? - it definetly wont work.

regards

RE: Hello World for MASM 32 !!

Didn't you have to run EXE2BIN on the .EXE to produce a .COM file that is located at 100h?

Or is it different with MASM 8?

rgds
Zeit.

RE: Hello World for MASM 32 !!

zeitghost,
Didn't you have to run EXE2BIN on the .EXE to produce a .COM file that is located at 100h?
You are right, for older MASM compiler and if you want to run it under real DOS-Mode.

Or is it different with MASM 8?
I think so. It already enhanced to make it compatible with 32 bit Windows. Notes, MASM 8 is not MASM version 8 the compiler is version 6.1x and there is no EXE2BIN

Aryajur,
I agree with oleksii. I think the biggest problem you have with your code is you are mixing memory addressing (using flat & stdcall) which is available under windows, but you are using DOS INT service in the code which is protected by windows.

Also can't we make console applications in MASM 32??
Please help.

Yes we can. If you want to go with 32bit asm for windows, go with API functions.
Look here for the example: Thread272-597553

-- AirCon --

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close