flat assembler
Message board for the users of flat assembler.

Index > DOS > [Newbie] MZ does not support multiple code labels?

Author
Thread Post new topic Reply to topic
fasmnewbie



Joined: 01 Mar 2011
Posts: 553
fasmnewbie
Hi people. very newbie here.

I tried this code in org and it worked. But when I changed the format to MZ, it says something about 'undefined symbol main .data', that is, my data segment. This program is to print a string using a loop to int 10h, function 0eh.

Code:
format MZ
entry .code:main

segment .code
main:
mov ax, .data ;error here
mov ds, ax
mov si, msg
mov cx, msglen
mov ah, 0eh

myLoop:
mov al, [si]
int 10h
inc si
loop myLoop

mov ah, 10h
int 16h
ret

segment .data
msg db 'Assembly Programming', 0dh, 0ah
msglen = $-msg               


If I comment out the erronous line, my program compiles fine but with undefined result of course. Similarly if I comment the entire myLoop chunks, it compiles fine (but garbage result).

Is it because I have two code labels there (main and myLoop) that altogether I have defined 3 segments? Or is it because of something else. Is having two code labels implying two different code segments?

This is my ORG version that works

Code:
org 100h

mov si, msg
mov cx, msglen
mov ah, 0eh

myLoop:
mov al, [si]
int 10h
inc si
loop myLoop

mov ah, 10h
int 16h
ret

msg db 'Assembly Programming', 0dh, 0ah
msglen = $-msg
    


Thanks for your kind replies.
Post 01 Mar 2011, 20:31
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17271
Location: In your JS exploiting you and your system
revolution
fasm uses labels starting with a single dot as local labels and will automatically attach the name to the previous non-local label. Just rename your sections so that they don't start with a single dot:
Code:
format MZ
entry codeseg:main

segment codeseg
main:
    mov     ax,dataseg
  mov     ds,ax
       mov     si,msg
      mov     cx,msglen
   mov     ah,0eh

myLoop:
   mov     al,[si]
     int     10h
 inc     si
  loop    myLoop

  mov     ah,10h
      int     16h
 ret

segment dataseg
  msg     db      'Assembly Programming',0dh,0ah
    msglen  =       $-msg    
Post 02 Mar 2011, 00:14
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 553
fasmnewbie
revolution wrote:
fasm uses labels starting with a single dot as local labels and will automatically attach the name to the previous non-local label. Just rename your sections so that they don't start with a single dot:
Code:
format MZ
entry codeseg:main

segment codeseg
main:
     mov     ax,dataseg
  mov     ds,ax
       mov     si,msg
      mov     cx,msglen
   mov     ah,0eh

myLoop:
   mov     al,[si]
     int     10h
 inc     si
  loop    myLoop

  mov     ah,10h
      int     16h
 ret

segment dataseg
  msg     db      'Assembly Programming',0dh,0ah
    msglen  =       $-msg    


That's one perfect answer. My code now works.

I thought that was a syntax requirement. Still can't get rid of that HLL syntax 'mentality'. That is because I keep seeing the dotted segment's name in everywhere an MZ format code appears, even in the Sample.

Thanks revo.
Post 02 Mar 2011, 10:43
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17271
Location: In your JS exploiting you and your system
revolution
The example that comes with fasm, MULTISEG.ASM, does not have dots in the names. I wonder which example you are referring to?
Post 02 Mar 2011, 10:48
View user's profile Send private message Visit poster's website 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.

Powered by rwasa.