flat assembler
Message board for the users of flat assembler.

Index > Main > Segments & Labels

Author
Thread Post new topic Reply to topic
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 22 Dec 2006, 03:08
My problem (of course related to the DPMI32 one discussed in DOS subforum):

Code:
; fasm example of writing multi-segment EXE program

format MZ
entry main:start            ; program entry point
stack 100h              ; stack size

segment main                ; main program segment

  start:
    mov ax,text
    mov ds,ax

    mov dx,hello
    call    extra:write_text

    mov ax,4C00h
    int 21h

segment text

  hello db 'Hello world!',24h

segment extra

  write_text:            ;Will be zero Wink
    mov ah,9
    int 21h
    retf

abc=1023

    bits = 16                ; Hack Sad
    display 'text '
    repeat bits/4
    d = '0' + write_text shr (bits-%*4) and 0Fh
    if d > '9'
        d = d + 'A'-'9'-1
    end if
    display d
    end repeat
    display 13,10
    


How to make FASM to list labels with their values ? Or is it impossible ?

The hack above (found in the manual) can display "ordinary" labels,
but NOT segment labels. Embarassed

In example above, what values do the labels "main", "text", and "extra"
have and how to display them ? Question

_________________
Bug Nr.: 12345

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

Status: Closed: NOT a Bug
Post 22 Dec 2006, 03:08
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 22 Dec 2006, 04:32
check here: listing for fasm 1.63 and higher (easiest to just download/use llaurrentt's package)

Usage: fasm myfile.asm myfile.exe myfile.lst
Post 22 Dec 2006, 04:32
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 22 Dec 2006, 09:27
rugxulo: For the values of labels much better is this one (also listed in Advanced Fasm Topics in Important/Interesting Threads - we really did something to make those things easier to find). The listing extension in its current form has been abandoned by me, I'm working on changes to fasm's core that may become a base for new better version.

As for the main question here: the segment labels in MZ format are an example of what is called relocatable symbol - their values are not known at the assembly time, and in case of segments the only value you can know from the assembler is the value of segment relative to some other segment.
So you can know "text-main" or "extra-main" value, however what value will "main" have you won't know until your program is run, and DOS may load your program with a different "main" base each time.
Post 22 Dec 2006, 09:27
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 22 Dec 2006, 16:46
rugxulo wrote:

Quote:
listing for fasm 1.63 and higher (easiest to just download/use llaurrentt's package)


Thanks. That is exactly what I needed. Smile

Tomasz wrote:

Quote:

much better is this one (also listed in Advanced Fasm Topics in Important/Interesting Threads


Does not work for me - need to include into an obsolete source version
no longer available. Confused

Quote:

As for the main question here: the segment labels in MZ format are an example of what is called relocatable symbol - their values are not known at the assembly time, and in case of segments the only value you can know from the assembler is the value of segment relative to some other segment.
So you can know "text-main" or "extra-main" value, however what value will "main" have you won't know until your program is run, and DOS may load your program with a different "main" base each time.


Thanks. Judging from this text, listing from "llaurrentt's package", and
some additional experiments:

- "main" becomes 0.

- If a segment is for ex. 50 bytes, it rounds up to 64, and the label
difference becomes 4.

- Every segment access will generate a reloc in the MZ header, and DOS
will patch all those values when loading the EXE.

- Failure of the "hack" on segment labels is NOT considered as bug Shocked

All ^^^ correct ?

Finally, I have to second the requests in the linked threads:
It would be nice to have the label listing feature in main FASM release,
rather than a patch usable with obsolete sources only.

_________________
Bug Nr.: 12345

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

Status: Closed: NOT a Bug
Post 22 Dec 2006, 16:46
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.