flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Linux > fasm for windows or linux

Author
Thread Post new topic Reply to topic
kerr



Joined: 24 Feb 2016
Posts: 124
fasm for windows or linux
Why fasm segment can be used within Windows environment. The data can only be used in the Linux section?

_________________
I hope we will be good friends.
Post 24 Feb 2016, 06:17
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3439
Location: Bulgaria
You need to explain your question in more detailed form. I simply can't understand what you mean.
Post 24 Feb 2016, 06:38
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 124
Re: fasm for windows or linux

kerr wrote:
Why fasm segment can be used within Windows environment. The data can only be used in the Linux section?


Linux environment cannot be used in the "segment .data"
print.asm [4]:
segment .data
error: extra characters on line.

_________________
I hope we will be good friends.
Post 24 Feb 2016, 07:34
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3439
Location: Bulgaria
If you are talking about compiling executable ELF file in Windows, after "segment" directive, only some flags can be set. Here is the quote from the FASM manual:

Quote:
and instead of section there should be the segment directive used, followed by one or more segment permission flags and optionally a marker of special ELF executable segment, which can be interpreter, dynamic or note. The origin of segment is aligned to page (4096 bytes), and available permission flags are: readable, writeable and executable.



For example, valid definitions are:

Code:
segment readable writeable executable
segment interpreter readable
segment readable writeable

Post 24 Feb 2016, 09:14
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 124

JohnFound wrote:
If you are talking about compiling executable ELF file in Windows, after "segment" directive, only some flags can be set. Here is the quote from the FASM manual:

Quote:
and instead of section there should be the segment directive used, followed by one or more segment permission flags and optionally a marker of special ELF executable segment, which can be interpreter, dynamic or note. The origin of segment is aligned to page (4096 bytes), and available permission flags are: readable, writeable and executable.



For example, valid definitions are:

Code:
segment readable writeable executable
segment interpreter readable
segment readable writeable




That is to say there is linux no code segment or data segment ? and no section .code or section data?

Code:

segment data
msg  db 'hello world!',0xa
segment code
mov eax,msg




Code:

section .data
msg  db 'hello world!',0xa
section .code
mov eax,msg



_________________
I hope we will be good friends.
Post 25 Feb 2016, 06:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15160
Location: GW170817
"code" and "data" are not sections that the OS knows, or cares, about. You (as the programmer) decide "code" by making a section "executable", and "data" by making it "readable/writeable". Or if you want something else just combine the flags as needed.

Even the definition of "data" is ambiguous. Do you want constant data or changeable data? Should it be initialised first or doesn't it matter?
Post 25 Feb 2016, 07:06
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 667
Kerr, section or segment depends on your target output.

If you are producing object files (.obj, .o), you have to comply with the linker's requirements you are using and most linkers require SECTION. NASM and MASM uses "sections" because they use linkers as part of the compilation process. FASM also uses "section" under Linux IF you are producing objects. But since FASM can produce executable directly without linkers, sections are not required. So people use flat format or segments to produce executable directly. This is for Linux.

In Windows it's a different story, FASM use sections because it's part of the PE format requirement, although not in its strictest sense. You can still use flat (no section, no segment). Segment is used if you want to produce MZ format.

So again, it depends on your target binary. Is it an obj/.o or is it an executable. The same goes to things like public, global, extern, _start, import etc. They all depend on target format.

Somebody please correct me if I am wrong. I don't want to mislead people on something like this.
Post 25 Feb 2016, 17:13
View user's profile Send private message Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 124

revolution wrote:
"code" and "data" are not sections that the OS knows, or cares, about. You (as the programmer) decide "code" by making a section "executable", and "data" by making it "readable/writeable". Or if you want something else just combine the flags as needed.

Even the definition of "data" is ambiguous. Do you want constant data or changeable data? Should it be initialised first or doesn't it matter?




Oh! i know system is cantnot distinguish data or code ,i think is compiler grammar set!

For example Nasm grammar:

Code:

segment .data
        msg     db "hello world",10
        len     equ $-msg
segment .text   
        global  _start:
_start:
        mov dx,len
        mov cx,msg
        mov bx,1
        mov ax,4
        int 80h
        mov bx,0
        mov ax,1
        int 80h



_________________
I hope we will be good friends.
Post 26 Feb 2016, 06:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15160
Location: GW170817
fasm != NASM, or MASM, or GASM, or TASM.
Post 26 Feb 2016, 07:02
View user's profile Send private message Visit poster's website Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 124

revolution wrote:
"code" and "data" are not sections that the OS knows, or cares, about. You (as the programmer) decide "code" by making a section "executable", and "data" by making it "readable/writeable". Or if you want something else just combine the flags as needed.

Even the definition of "data" is ambiguous. Do you want constant data or changeable data? Should it be initialised first or doesn't it matter?




system error ,You said no wrong!

i Speak mean Windows for fasm grammar and linux for fasm grammar ,why not same it?


For example Windows for Fasm grammar:

Code:

format MZ
entry .code:start
segment .code
start:
mov ax.data
mov dsax   
mov dxmsg   
mov ah9h
int 21h
mov ah4ch
int 21h
segment .data
msg db 'Hello World''$'




For example Linux for fasm grammar :

Code:

format ELF executable 3
entry start
segment readable writeable executable 
start:

        mov     eax,4
        mov     ebx,1
        mov     ecx,msg
        mov     edx,msg_size
        int     0x80

        mov     eax,1
        xor     ebx,ebx
        int     0x80
msg db 'Hello world!',0xA
msg_size = $-msg





this is windows grammar you can use "section .code"or "segment .code" and "entry start" can replace "public start"! but ,linux use "section .code" or "segment .code" and "entry start" can replace "public start" prompt error!

main1.asm [2]:
public start
error: illegal instruction.
segment .code
error: invalid argument.
section .code
error: illegal instruction.
Is it did i understand fasm for window or linux grammar wrong?

_________________
I hope we will be good friends.
Post 26 Feb 2016, 07:06
View user's profile Send private message Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 124

revolution wrote:
fasm != NASM, or MASM, or GASM, or TASM.



Oh! that is to say , windows for fasm and linux for fasm grammar is not same it?

_________________
I hope we will be good friends.
Post 26 Feb 2016, 07:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15160
Location: GW170817
fasm does not have ".code" or ".data" anywhere in its internals. If you see them in code then they are macros that expand to something else.
Post 26 Feb 2016, 07:12
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3439
Location: Bulgaria
kerr, this is not different "grammar". The different directives in your examples are simply because of the different binary formats FASM compiles. The best way to improve your knowledge is simply to read carefully the FASM manual. All these details are explained there.

Also, as revolution noticed, you must learn to separate FASM directives from FASM macros.
Post 26 Feb 2016, 07:44
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 124

revolution wrote:
fasm does not have ".code" or ".data" anywhere in its internals. If you see them in code then they are macros that expand to something else.




on windows or linux fasm grammar is that no standard ?

_________________
I hope we will be good friends.
Post 26 Feb 2016, 07:44
View user's profile Send private message Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 124

JohnFound wrote:
kerr, this is not different "grammar". The different directives in your examples are simply because of the different binary formats FASM compiles. The best way to improve your knowledge is simply to read carefully the FASM manual. All these details are explained there.

Also, as revolution noticed, you must learn to separate FASM directives from FASM macros.



Oh yeah!Can I get a full manual in what place? format pdf file

_________________
I hope we will be good friends.
Post 26 Feb 2016, 07:54
View user's profile Send private message Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 124

Quote:

Thank you @JohnFound @revolution @system error

Post 26 Feb 2016, 08:10
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 667
kerr, I won't blame you if you are confused.

1. If you want to produce EXECUTABLES (.exe, .a;

in Linux, use segment or flat (no segment no section)
in Windows, use segment (for MZ 16-bit), section (for PE, PE64) or flat.
in DOS, use "org".


2. If you want to produce OBJECTS (by using linker, .o, .obj);

in Linux, use section ".text" executable, section ".data" writeable
in Windows, use section (COFF, MS COFF format)

So which one that you want to produce? An object or an executable? Answer this question first and then pick one format that is suitable for such purpose.

By the way, most of the NASM examples you been reading are using linkers, that is they compile to objects. That's why they use section .text, section .data, section .bss. But unfortunately, FASM can produce executables directly without using linkers, so most FASM examples you see use segments instead of section.

BUT....

if you want to use FASM to produce objects (like NASM always do), here's the equivalent example;


Code:
format ELF ;this is for Linux. Don't confuse this for Windows

public _start

section '.text' executable
_start:
        mov edx,len 
        mov ecx,msg 
        mov ebx,1 
        mov eax,4 
        int 80h 
        mov ebx,0 
        mov eax,1 
        int 80h 

section '.data' writeable
msg db "hello world",10 
len  = $-msg 



I haven't tested this but it should work.
Post 26 Feb 2016, 08:23
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3439
Location: Bulgaria

kerr wrote:
Oh yeah!Can I get a full manual in what place? format pdf file



Full FASM manual is packed inside every FASM package you download from FlatAssembler web site. All these packages use different text formats for shipping the manual.

If you need exactly PDF - download the package for Windows.

Also, the manual is published online here: FASM manual. You can read it in your web browser.

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 26 Feb 2016, 09:10
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 124

system error wrote:
kerr, I won't blame you if you are confused.

1. If you want to produce EXECUTABLES (.exe, .a;

in Linux, use segment or flat (no segment no section)
in Windows, use segment (for MZ 16-bit), section (for PE, PE64) or flat.
in DOS, use "org".


2. If you want to produce OBJECTS (by using linker, .o, .obj);

in Linux, use section ".text" executable, section ".data" writeable
in Windows, use section (COFF, MS COFF format)

So which one that you want to produce? An object or an executable? Answer this question first and then pick one format that is suitable for such purpose.

By the way, most of the NASM examples you been reading are using linkers, that is they compile to objects. That's why they use section .text, section .data, section .bss. But unfortunately, FASM can produce executables directly without using linkers, so most FASM examples you see use segments instead of section.

BUT....

if you want to use FASM to produce objects (like NASM always do), here's the equivalent example;


Code:
format ELF ;this is for Linux. Don't confuse this for Windows

public _start

section '.text' executable
_start:
        mov edx,len 
        mov ecx,msg 
        mov ebx,1 
        mov eax,4 
        int 80h 
        mov ebx,0 
        mov eax,1 
        int 80h 

section '.data' writeable
msg db "hello world",10 
len  = $-msg 



I haven't tested this but it should work.




Yes! You speak very good! but this code Need a compiler and linkers ld ! Making process 。

but flat compile An executable program Need to access !

_________________
I hope we will be good friends.
Post 26 Feb 2016, 09:29
View user's profile Send private message Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 124

JohnFound wrote:

kerr wrote:
Oh yeah!Can I get a full manual in what place? format pdf file



Full FASM manual is packed inside every FASM package you download from FlatAssembler web site. All these packages use different text formats for shipping the manual.

If you need exactly PDF - download the package for Windows.

Also, the manual is published online here: FASM manual. You can read it in your web browser.



in browser read is very trouble!

_________________
I hope we will be good friends.
Post 26 Feb 2016, 09: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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.