flat assembler
Message board for the users of flat assembler.

Index > Main > strange include in format mz (newbie only for asm lang)

Author
Thread Post new topic Reply to topic
muratselim



Joined: 21 Aug 2007
Posts: 13
muratselim
Code:
format MZ ;define the type of program

stack 200h ;define the stack size

entry cod:Start

 segment dat ;define the data segment

 Message db "Hello World" ;the data

 segment cod

 Start: ;start the program

 mov ax, dat ;move the segment of Message to the accumulator
 mov dx, Message ;move the offset of Message to displacement register
 mov ds, ax ;move segment of Message to data segment register

 call Write_String ; in the subfunc.inc

 ;mov ah, 09h ;move 9 to the accumulator
 ;int 21h ;perform interrupt 33
 mov ah, 00h ;move 0 to the accumulator
 int 16h ;perform interrupt 22

 mov ax, 4c00h ;move the close program directive to the accumulator
 int 21h ;perform interrupt 33         
include 'subfunc.inc' ; only works here

      


is there a way to include in the begining of source. thanks for any response
Post 21 Aug 2007, 06:47
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Code:
include 'subfunc.inc' ; only works here    


Strange Confused - and secret ? Question

Have a look at COMDEMO & EXEDEMO examples, and here:

http://board.flatassembler.net/topic.php?t=6735 Idea

No need to deal with segments (unlike in MA$M) or include any junk Idea

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 21 Aug 2007, 07:15
View user's profile Send private message Reply with quote
muratselim



Joined: 21 Aug 2007
Posts: 13
muratselim
i haven't seen any include directive in the example other than simulating
win executables format...
can you give a small sample mz which uses include directive in the begining
i need it to modular codding

BTW, thanks for fast response
Post 21 Aug 2007, 07:28
View user's profile Send private message Reply with quote
muratselim



Joined: 21 Aug 2007
Posts: 13
muratselim
Code:
 Write_String:     ; Writes string from DS:SI until character #0 is met
        mov ah, 0xE     
        xor bh, bh      
        mov bl, 0x7
  .nextchar:
        lodsb           
        or al,al
        jz .return
        int 10h 
        jmp .nextchar
  .return:
        ret
    

if that helps...
Post 21 Aug 2007, 07:57
View user's profile Send private message Reply with quote
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie
You can put your include file earlier on but just be sure that the contents do not get executed when it should not. If you are calling a subroutine from it, then an unexpected ret will crash the program. You could try jumping over it by puting a jump instruction at the beginning of the include file and a label at the end to jump to. But there is nothing wrong with leaving it at the end of the source for simple programs.
Post 21 Aug 2007, 08:07
View user's profile Send private message Reply with quote
muratselim



Joined: 21 Aug 2007
Posts: 13
muratselim
Code:

format MZ ;define the type of program

stack 200h ;define the stack size

  jmp Start
 include 'subfunc.inc'

entry cod:Start


 segment dat ;define the data segment

 Message db "Hello World" ;the data

 segment cod

 Start: ;start the program
 mov ax, dat ;move the segment of Message to the accumulator
 mov dx, Message ;move the offset of Message to displacement register
 mov ds, ax ;move segment of Message to data segment register

 call Write_String

 ;mov ah, 09h ;move 9 to the accumulator
 ;int 21h ;perform interrupt 33
 mov ah, 00h ;move 0 to the accumulator
 int 16h ;perform interrupt 22

 mov ax, 4c00h ;move the close program directive to the accumulator
 int 21h ;perform interrupt 33
                                     
    


this doesnt work. where i can put it?


Last edited by muratselim on 21 Aug 2007, 08:58; edited 1 time in total
Post 21 Aug 2007, 08:13
View user's profile Send private message Reply with quote
muratselim



Joined: 21 Aug 2007
Posts: 13
muratselim
Code:

format MZ ;define the type of program

stack 200h ;define the stack size
; right place here
entry cod:Start


 segment dat ;define the data segment

 Message db "Hello World" ;the data

 segment cod

 Start: ;start the program
 jmp main
  include 'subfunc.inc'
 main:
 mov ax, dat ;move the segment of Message to the accumulator
 mov dx, Message ;move the offset of Message to displacement register
 mov ds, ax ;move segment of Message to data segment register

 call Write_String

 ;mov ah, 09h ;move 9 to the accumulator
 ;int 21h ;perform interrupt 33
 mov ah, 00h ;move 0 to the accumulator
 int 16h ;perform interrupt 22

 mov ax, 4c00h ;move the close program directive to the accumulator
 int 21h ;perform interrupt 33
     


reosanabely okey its working but not good proggramming practice...

thanks for all response if you have better solution please post it[/code]
Post 21 Aug 2007, 08:23
View user's profile Send private message Reply with quote
daluca



Joined: 05 Nov 2005
Posts: 86
daluca
Hi muratselim: sorry for the late reply.

if you want to include the file at the begining,first must realize that it has to be put inside some segment,if you put it in another segment rather than your
cod segment then you must do a far call(I haven't use dos for a time so i don't remember how you do that)
but if you want to put it at the begining of your cod segment the right would be:

Code:

format MZ
stack 200h
entry cod:Start


segment dat

         Message db "Hello World"

segment cod
         include 'subfunc.inc'
Start:

         mov ax, dat
         mov dx, Message
         mov ds, ax

         call Write_String

         mov ah, 00h
         int 16h
         mov ax, 4c00h
         int 21h                         

    


but if you do it only prints garbage.
the reason?

you design your Write_String function to write the string pointed by ds:si
but in your code you move Message to dx not to si,so if you change:

Code:

         mov dx, Message

    


for:

Code:

         mov si, Message

    


it works now.

but...

if the SI wasn't initialized properly in the other examples,why puting the function at the end or jumping over it worked?

well it looks like at program startup SI holds your program entry point:
then leaving your program entry point at the begining of the cod segment
makes the program entry = 0000 and since the offset of the Message string
is at offset 0000 (in the dat segment) SI luckily point to the right place.

but if you include your 'subfunc.inc' at the begining of the segment then
the entry point is displaced and that is why it prints garbage.

and 2 more things:

you forgot to put a 0 at the end of the string,in this case it dosn't matter since the string will be follow by a bunch of zeros but is a good proggramming practice.

in your Write_string function you are assumming tha the direction flag is cleared what may not be the case always so it may be a good thing to include a cld in the initialization part.



regards.
Post 30 Aug 2007, 16:42
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 GitHub, YouTube, Twitter.

Website powered by rwasa.