flat assembler
Message board for the users of flat assembler.

Index > Main > mz segments

Author
Thread Post new topic Reply to topic
Feggger



Joined: 19 Apr 2006
Posts: 8
Feggger
Hi!

I want to assemble this code:
Code:
format mz
segment a
    mov ah, 09h
    mov dx, msg1
segment b
    msg1 db 'x',0
segment a
    int 21h
    ret    


but i have error:
segment a
error: symbol already defined.

How to combine two "a" segments into one?
Post 19 Sep 2006, 13:50
View user's profile Send private message Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista
Hello Fegger, and welcome to the FASM board.
If you want to print a message to the screen, you can try this simple example:
Code:
org 100h 

jmp start 

; Print Routine 
print: 
        mov ah,9h 
        int 21h 
        ret 

print_wait: 
        call print 
        xor ax,ax   ; pause screen until user hits any key 
        int 16h 
        jmp exit 

; Message Text 
msg1 db 'x', 13, 10, '$' 

start: 
        mov dx,msg1 
        call print_wait 

         
exit:
     mov ax, 4c00h
     int 21h

 
    




No need for "MZ" or segments. I'm fairly new to asm programming and I've gotten lots of help, encouragement, and support on this forum. you're lucky to have found fasm. i know i am.

NOTE: code example has not been tested
Post 19 Sep 2006, 14:43
View user's profile Send private message Visit poster's website Reply with quote
Feggger



Joined: 19 Apr 2006
Posts: 8
Feggger
Thank you, HyperVista, but i do not want to print a string.
I want to combine two segments of mz exe file with same name into one.
Post 19 Sep 2006, 15:03
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
I think he wants to "reopen" a segment to add more data/code. I never used MZ format in FASM but I think it's not possible to do that. However you can use some macros like the ones included in fresh to define global data maybe.
Post 19 Sep 2006, 15:06
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
;**********************************************
; Macroses for global variables handling.
; This macro library is part of Fresh project.
;
; (C)2003, 2004
;
; Authors:
;   John Found
;   Tomasz Grisztar
;
; usage:
;   1. Include this library in the begining
;      of your source file.
;   2. Use it as blocks anywhere in the source.
;        iglobal
;           somelabel dd 1234h
;           otherlabel RECT
;           lbl3       db 12h
;        endg
;
;   3. Data section must be at the end of the
;      source file. Use 'IncludeAllGlobals' to
;      really define variables.
;
;**********************************************


macro _iglobal dummy { IGlobals equ IGlobals,
                       macro __IGlobalBlock { }

macro _uglobal dummy { UGlobals equ UGlobals,
                       macro __UGlobalBlock { }


iglobal fix _iglobal } _iglobal
uglobal fix _uglobal } _uglobal
endg fix }

macro IncludeIGlobals { macro _iglobal dummy \{ \}
                        macro _uglobal dummy \{ \}
                        macro IGlobals dummy,[n] \{ __IGlobalBlock
                                                    purge __IGlobalBlock \}
                        match I, IGlobals \{ I \} }


macro IncludeUGlobals { macro _iglobal dummy \{ \}
                        macro _uglobal dummy \{ \}
                        macro UGlobals dummy,[n] \{ \common \local begin, size
                                                     begin = $
                                                     virtual at $
                                                    \forward
                                                     __UGlobalBlock
                                                     purge __UGlobalBlock
                                                    \common
                                                     size = $ - begin
                                                     end virtual
                                                     rb size \}
                        match U, UGlobals \{ U \} }

;--------------------------------------------
; constStr Str1, 'This is string constant'
;--------------------------------------------
macro constStr  lbl, text {
  __StringsArray equ __StringsArray, lbl, text     ;  add to the list
}


macro __IncludeStringConstants dummy,[lbls, text] {
  forward
    if text eqtype 'A'
      lbls db text
      sizeof.#lbls = $ - lbls
      db 0
    else
      if text eqtype 0
        lbls = text
      end if
    end if
}

macro IncludeStringConstants {
 match strings, __StringsArray \{ __IncludeStringConstants strings \}

}


__StringsArray equ

macro IncludeAllGlobals {
  local begin

  begin = $
  IncludeIGlobals

  align 4

  begin = $
  IncludeStringConstants

  align 4

  begin = $
  IncludeUGlobals
}

iglobal
endg

uglobal
endg

format mz
segment a 
    mov ax, b
    mov ds, ax

    mov ah, 09h
    mov dx, msg1
iglobal
    msg1 db 'Hello world!!$',0
endg
    int $21
    xor ax, ax
    int $16

    mov ax, $4c00
    int $21
segment b
  IncludeAllGlobals    


Seems to works fine. Hope that this is what you want
Post 19 Sep 2006, 15:17
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
what you want (merge segments with same name) is job of linker. when you use FASM to produce MZ file, you are omitting linking (FASM is assembler, not linker). So there are 3 segments created instead
Post 19 Sep 2006, 20:44
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Feggger



Joined: 19 Apr 2006
Posts: 8
Feggger
But what about pe exe? In pe exe sections with same name merged.

Why this can't be done in mz exe?

locodelassembly: thanks. I'll try now.
Post 20 Sep 2006, 08:15
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
But what about pe exe? In pe exe sections with same name merged.

they are? are you sure?
Post 20 Sep 2006, 08:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Feggger



Joined: 19 Apr 2006
Posts: 8
Feggger
locodelassembly: Thank you. It works!

vid: You right. This is not supported Sad This supported only with external linker...
Post 20 Sep 2006, 14:46
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
PE sections can have every name (but no longer than 8 bytes) and they are meaningless for working. You can name all sections '.code' or all sections 'fasm rox' Smile. It doesn;t matter, but remember that every time you put section 'xxx' readable', etc. in your source, fasm creates another section. It doesn't merge anything.
Post 20 Sep 2006, 19:52
View user's profile Send private message Visit poster's website Reply with quote
Feggger



Joined: 19 Apr 2006
Posts: 8
Feggger
Thanks all. This is my simplified version of Fresh macroses:
Code:
macro   .model [dummy]
{
common
        _segment text
}


macro _segment name
{
        local   mac
        __#name equ __#name, mac
        macro mac
        {
}

macro   _end [segments]
{
common
local   mac
        macro mac dummy,[n]
        \{
                n
                purge n
        \}
forward
        Segment segments
        match I, __#segments
        \{
                mac I
        \}
}

.end fix } _end
.segment fix } _segment
    


How to use:
Code:
format mz
include 'mz.inc'
.model small

        mov ax, msgs
        mov ds, ax

        mov ah, 09h
        mov dx, msg1

.segment msgs
        msg1 db 'Hello world!!$',0

.segment text
        int $21
        xor ax, ax
        int $16

.segment msgs
        msg2 db 'message2', 0

.segment text
        mov ax, $4c00
        int $21

.end    text, msgs
    


This version puts on result code data of forward, not reversed order. And easily can be written macroses for merging needed segments (analog of masm DGROUP).

locodelassembly, thank you again.
Post 21 Sep 2006, 16:33
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.