flat assembler
Message board for the users of flat assembler.

Index > DOS > Why my simple code doesn't compile?

Author
Thread Post new topic Reply to topic
Juhas



Joined: 23 Apr 2012
Posts: 4
Juhas
Hi, I'm freaking out. This is the third day of reading various docs and board messages and I still don't know why my code doesn't compile.

Code:
format mz
entry .code:start

segment .data
  s db 'Hello$'

segment .code
start:
  mov ax, .data         ; sets data segment
  mov ds, ax

  mov dx, s
  call .proc:print
  call .proc:wait_key

  mov ah, 4ch
  int 21h

segment .proc
wait_key:
  mov ah, 01h
  int 21h
ret

print:
  mov ah, 09h
  int 21h
ret       

I get error message: undefined symbol: '.code' in the second line(entry)

When I try to compile this one(segment names without periods:

Code:
format mz
entry code:start

segment data
  s db 'Hello$'

segment code
start:
  mov ax, data         ; sets data segment
  mov ds, ax

  mov dx, s
  call proc:print
  call proc:wait_key

  mov ah, 4ch
  int 21h

segment proc
wait_key:
  mov ah, 01h
  int 21h
ret

print:
  mov ah, 09h
  int 21h
ret            

I get: Invalid argument on line: "segment data"

But, when I do something like that:
Code:
format mz
entry .code:start

segment .code
wait_key:
  mov ah, 01h
  int 21h
ret

print:
  mov ah, 09h
  int 21h
ret

start:
  mov ax, .data         ; sets data segment
  mov ds, ax

  mov dx, s
  call print
  call wait_key

  mov ah, 4ch
  int 21h

segment .data
  s db 'Hello$'

    

Everything works fine!

Why is that?
Do I have to name every segment starting with period(.)?
Does .code segment must be the first segment?
Can I have subprograms in place where I want, or they MUST be before "start" label?
Post 23 Apr 2012, 17:26
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1399
Location: Toronto, Canada
AsmGuru62
If your code can fit into 64Kb -- you can use COM file instead of MZ EXE file.
COM is a flat model - very easy to program.
No need to set up any segments - they are all the same and set up by DOS.
Post 23 Apr 2012, 17:38
View user's profile Send private message Send e-mail Reply with quote
Juhas



Joined: 23 Apr 2012
Posts: 4
Juhas
But I want to learn how to make exec's.
Post 23 Apr 2012, 19:57
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4226
Location: 2018
edfed
you can start from examples in the DOS fasm package. you will have exactlly all the minimal stuff to do .exe with fasm, and i think it is the only sure reference for fasm initiation.

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:
        mov     ah,9
        int     21h
        retf
    

i think the problem, in the first code, is that .code may be interpreted as a local label relative to s label in the .data segment. then, to access the full name, you will have to write:
Code:
entry s.code:start    

to get correct compile.

in the second code, data is a reserved word (used to define the permissions of a segment or section) if i well remember, then, cannot be used as a label to define a segment, or anything else.
Post 23 Apr 2012, 20:05
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.