flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
kerr 24 Feb 2016, 06:17
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. |
|||
![]() |
|
JohnFound 24 Feb 2016, 06:38
You need to explain your question in more detailed form. I simply can't understand what you mean.
|
|||
![]() |
|
JohnFound 24 Feb 2016, 09:14
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 |
|||
![]() |
|
kerr 25 Feb 2016, 06:07
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: 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. |
|||
![]() |
|
revolution 25 Feb 2016, 07:06
"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 25 Feb 2016, 17:13
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. |
|||
![]() |
|
kerr 26 Feb 2016, 06:15
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. 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. |
|||
![]() |
|
revolution 26 Feb 2016, 07:02
fasm != NASM, or MASM, or GASM, or TASM.
|
|||
![]() |
|
kerr 26 Feb 2016, 07:06
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. 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 ds, ax mov dx, msg mov ah, 9h int 21h mov ah, 4ch 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. |
|||
![]() |
|
kerr 26 Feb 2016, 07:11
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. |
|||
![]() |
|
revolution 26 Feb 2016, 07:12
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.
|
|||
![]() |
|
JohnFound 26 Feb 2016, 07:44
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. |
|||
![]() |
|
kerr 26 Feb 2016, 07:44
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. |
|||
![]() |
|
kerr 26 Feb 2016, 07:54
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. Oh yeah!Can I get a full manual in what place? format pdf file _________________ I hope we will be good friends. |
|||
![]() |
|
kerr 26 Feb 2016, 08:10
Quote:
|
|||
![]() |
|
system error 26 Feb 2016, 08:23
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. |
|||
![]() |
|
JohnFound 26 Feb 2016, 09:10
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 |
|||
![]() |
|
kerr 26 Feb 2016, 09:29
system error wrote: kerr, I won't blame you if you are confused. 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. |
|||
![]() |
|
kerr 26 Feb 2016, 09:33
JohnFound wrote:
in browser read is very trouble! _________________ I hope we will be good friends. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.