flat assembler
Message board for the users of flat assembler.

Index > DOS > Little problem with Hello World!

Author
Thread Post new topic Reply to topic
prana



Joined: 28 Aug 2003
Posts: 51
prana 06 Sep 2003, 15:34
What's wrong in this program listed below?

___________________________________________
Code:
format  MZ

entry          code:main
stack          100h

segment         data    use16
msg             db      "Hello World!$"

segment         code   use32
main:           mov     ax,data
                mov     ds,ax
                mov     dx,msg
                mov     ah,9
                int     21h

                mov     ax,4c00h
                int     21h
                retf           
    

________________________________________________________

And If I try to write it using MS COFF and COFF format how this should be restructured?

Thanks for all your help.
Post 06 Sep 2003, 15:34
View user's profile Send private message Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 06 Sep 2003, 15:47
I'm no expert at this, but shouldn't there be an "org 100h"? (.COM needs it)

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 06 Sep 2003, 15:47
View user's profile Send private message Visit poster's website Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana 06 Sep 2003, 16:02
COM files! with segments. MZ can also be exe files as well, I believe. Rolling Eyes
I am a little confused honestly.
And hence I am lookin for the COFF and MS COFF variations of the code too.
Post 06 Sep 2003, 16:02
View user's profile Send private message Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 06 Sep 2003, 16:15
You can't use the names code and data.... Use something else, such as text, _code or something.... Wink
Post 06 Sep 2003, 16:15
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 06 Sep 2003, 17:25
Tommy is right, with such correction it should be OK.
And COFF format is suitable only for 32-bit code with flat addressing, you cannot define 16-bit segments there.
Post 06 Sep 2003, 17:25
View user's profile Send private message Visit poster's website Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana 06 Sep 2003, 17:41
Thanks guys! Smile

The use32 directive has no meaning as used here then? MZ files can also be exe files. isn't it true?

Privalov, in COFF and MS COFF, I use section directive. How this differs from segment directive? Please enlighten me.

Also I changed the code as per your suggestion:

___________________
Code:
format  MZ

entry          _code:main
stack          100h

segment         _data    use32
msg             db      "Hello World!$",0

segment         _code    use32
main:           mov     ax,_data
                mov     ds,ax
                mov     dx,msg
                mov     ah,9
                int     21h

                mov     ax,4c00h
                int     21h
                retf          
    

____________________________________

This compiles, but my NTVDM cannot execute this, why? Do I need a real DOS box?

And lastly, is there any end directive in FASM?

Thanks for your help.
Post 06 Sep 2003, 17:41
View user's profile Send private message Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 06 Sep 2003, 18:02
Why are you using the use32-directive??? DOS-applications are 16-bits apps. (with some exceptions when we're talking about PM etc.)...
Post 06 Sep 2003, 18:02
View user's profile Send private message Visit poster's website Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana 06 Sep 2003, 18:35
Ok then...my mistake. Embarassed

What about my other questions?
Could u pls help?
Post 06 Sep 2003, 18:35
View user's profile Send private message Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 06 Sep 2003, 19:06
Code:
format MZ

entry _code:main
stack 100h

segment _data
msg db "Hello World!$",0

segment _code
main:
mov ax,_data
mov ds,ax
mov dx,msg
mov ah,9
int 21h

mov ax,4c00h
int 21h    

Here's a version of working code... Wink Your other question? Do you mean that one about the end-directive?
Post 06 Sep 2003, 19:06
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 06 Sep 2003, 20:30
Prana,

Did you check the Comdemo example from the FASM package? Very Happy

Code:
; fasm example of writing 16-bit COM program

 org     100h                    ; code starts at offset 100h
        use16                           ; use 16-bit code

display_text = 9

       mov     ah,display_text
     mov     dx,hello
    int     21h

     int     20h

hello db 'Hello world!',24h
    

_________________
Code it... That's all...
Post 06 Sep 2003, 20:30
View user's profile Send private message Visit poster's website Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana 07 Sep 2003, 03:45
Sorry for the late reply.

Thanks Tommy, I've figured that out! Smile
Tommy, my other questions were:
1) The end directive
2) Is there any PROC macro, and an example of when and how this is used.
3) In COFF and MS COFF, FASM uses section directive. How this differs from segment directive?

Vortex, thanks to you too, but I wanted to create an .exe file, not a .com file.

However, some explanatory answers for the above questions would help a lot.
Post 07 Sep 2003, 03:45
View user's profile Send private message Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 07 Sep 2003, 06:58
Hi prana,

I'm not sure about all the questions, but conserning number 1: I don't think there is such a directive, and I don't think you need it in FASM either (I'm not sure how the end-directive you are talking about works, since I've always used FASM when programming in assembly - and that's just 2 years or something).
Question number 2: There's a proc-macro for 32-bits applications, but not any for 16-bits apps. (as far as I know). That shouldn't be too hard to make, should it Privalov (I'll try to make one Wink)?

I think the smartest thing is to ask Privalov or someone else with a bit more experience than me (I'm only 16) about the last question - since they know more about FASM and assembly.

So long!
Tommy
Post 07 Sep 2003, 06:58
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 07 Sep 2003, 09:23
In very general, the section is just a part of segment, and 32-bit programs with flat addressing (and for such programs PE/COFF and ELF formats are designed) use only one large segment (of limit 4 GB) which contains whole addressing space, and many sections are mapped into this segment. In the 16-bit MZ format one segment has a limit of 64 KB, therefore you may need to use more segments for larger programs.
This is just a quick overview to give you idea of what is the difference between segments and sections, but if you want some really good information on such topics, I suggest waiting for my tutorial to be finished. I've started working more intensively on it, and the progress should be faster soon.
Post 07 Sep 2003, 09:23
View user's profile Send private message Visit poster's website Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer 07 Sep 2003, 10:00
prana wrote:
1) The end directive


To point out entry point you can use "entry" directive instead.

prana wrote:
2) Is there any PROC macro, and an example of when and how this is used.


The "proc", "return" and "stdcall" macroses can be easily adapted for 16-bit programming:

Code:
; macroinstructions for defining and invoking stdcall HLL procedures

macro proc name,[arg]                   ; define procedure
 { common
    name:
    virtual at ebp+4
    if ~ arg eq
   forward
     local ..arg
     ..arg dw ?
     arg equ ..arg
   common
     end if
     ..ret = $ - (ebp+4)
    end virtual
    local ..dynamic_data,..dynamic_size
    dynamic_data equ ..dynamic_data
    dynamic_size equ ..dynamic_size
    virtual at ebp - dynamic_size
     dynamic_data: }

macro enter                             ; begin procedure instructions
 { rb (2 - ($-dynamic_data) and 1b) and 1b
   dynamic_size = $ - dynamic_data
   end virtual
   enter dynamic_size,0 }

macro return                            ; return from procedure
 { leave
   ret ..ret }

macro stdcall proc,[arg]                ; call procedure
 { reverse
    push arg
   common
    call proc }
    


The only disadvantage is that you you can use only words as parameters of procedure.

_________________
Best regards,
Antoch Victor
Post 07 Sep 2003, 10:00
View user's profile Send private message Yahoo Messenger Reply with quote
prana



Joined: 28 Aug 2003
Posts: 51
prana 07 Sep 2003, 12:05
What can I say, thank you all so much Very Happy

And will be very eagerly waiting for Privalov's tutorial, it would definitely help me a lot.

Just one more question regarding 4 GB mem limit. If I use segment registers along with paging, can't I get more memory addressing capability? Is there any way of doing that?
Post 07 Sep 2003, 12:05
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.