Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello World for MASM 32 !!

Status
Not open for further replies.

aryajur

Programmer
Jul 2, 2003
45
US
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.
 
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)
 
Well I tried that also but still it doesn't work !!!
Any more ideas???
 
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)
 
I tried that as well still the same !!! :-(
 
Does int21 "know" you're using a 32 bit offset (EDX) in stead of a 16 bit one (DX)?

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
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...
Code:
; 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
 
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.

:)
 
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)
 
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
 
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.
 
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 --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top