flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Nice GAS feature ".end"

Author
Thread Post new topic Reply to topic
fasmnewbie



Joined: 01 Mar 2011
Posts: 529
Been playing with GAS lately. One nice feature of GAS is the

.end

directive which is optional btw. Ofc it's not the directive per se that interests me but rather the fact that the assembler ignores literally everything that comes after it.

My thought: Wouldn't it be nice for FASM to have this kind of feature where a group of texts and supplementary comments can be placed somewhere or anywhere for documentation purposes independent of the coding area? Ofc we can always put side-comments or top-comments among the codes but there are times when it is more productive and effective to have a place where lengthy internal documentations can be put outside the 'crowds', without needing any special symbols. It gives you a better sense of completion.

Like this... (free-texts at the bottom);
Code:
#       DEMO     : Using GNU Assembler & BASELIB (base6.o)
#       Compile  : as this.asm -o this.o
#       Link     : ld this.o base6.o -o this
.data
.align 16
        num: .quad 0x45,0x56
        xyz: .double 0f+456.4456

.text
.global _start
_start:
        mov     $_start,%rax
        mov     $num,%rbx
        call    dumpreg
        
        push    (num+8)
        mov     $10,%rax
        call    stackview
        
        mov     (xyz),%rax
        call    prndbl
        call    exitx
.end

These comments are ignored by the assembler after the .end directive. 
Now I am free to write some notes for this little code outside the busy coding 
area. AT&T syntax is confusing. This is within the same source    


Just a thought.


Last edited by fasmnewbie on 17 Jan 2018, 04:07; edited 1 time in total
Post 17 Jan 2018, 01:15
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: 16057
Location: 112 Ocean Avenue, Amityville
What name would you suggest for fasm? ".end" is already in use for the Windows library and import macros.
Post 17 Jan 2018, 03:39
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 529
I prefer ".footnote" because it gives the idea that it should be put at the end of the source and nowhere else. Or ".nb" perhaps. I don't know... just a thought. It should give users more freedom in documenting their codes (useful for students too!)
Post 17 Jan 2018, 03:53
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: 16057
Location: 112 Ocean Avenue, Amityville
Or perhaps:
  • postscript
  • done
  • end
  • finished
Using "end" might be good since it is already defined, so there would be no need for a new keyword.
Post 17 Jan 2018, 04:50
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 191
Location: Russian Federation, Sochi
may be sth name like force_eof
End source will be hard to port in concepts of fasmg, but some kind of alternate end of file could.
Post 17 Jan 2018, 05:53
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6968
Location: Kraków, Poland
For fasmg it has been briefly discussed here: https://board.flatassembler.net/topic.php?p=190291#190291

Note that all fasm versions since the beginning respect the actual EOF byte or a null byte to terminate the file. If the editor you use is able to handle inserting such bytes in a middle of text, you can use them for such purpose.
Post 17 Jan 2018, 09:03
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: 16057
Location: 112 Ocean Avenue, Amityville
Tomasz Grysztar wrote:
Note that all fasm versions since the beginning respect the actual EOF byte or a null byte to terminate the file. If the editor you use is able to handle inserting such bytes in a middle of text, you can use them for such purpose.
While some editors can do such tricks, it is not common. And it isn't potable. If someone posts code here using the EOF byte a lot of people won't be able to properly use it or see it. Copy and paste will be difficult.

Testing for some control characters:
Code:
text.

Text after control characters.    
I don't see any of those characters
Post 17 Jan 2018, 09:50
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6968
Location: Kraków, Poland
revolution wrote:
While some editors can do such tricks, it is not common. And it isn't potable. If someone posts code here using the EOF byte a lot of people won't be able to properly use it or see it. Copy and paste will be difficult.
Yes, this is all true. But the same code in preprocessor could be easily expanded to recognize any special sequence of characters to serve the same purpose (note that this would not be a real "directive" as this sequence would be recognized at the time of reading the file for preprocessing). And as this would be a feature of preprocessor, it would not need to be present in fasmg, which already has tools for doing this with macros anyway.
Post 17 Jan 2018, 12:01
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1264
Code:
macro footnote
{
These comments are ignored by the assembler after the .end directive. 
Now I am free to write some notes for this little code outside the busy coding 
area. AT&T syntax is confusing. This is within the same source
}    
I honestly don't see what's wrong with 'comments' though, at least the reader won't be confused if the footnote is really long.

On a side-note, .end is actually really useful for "hacks" (but it has nothing to do with FASM) Razz You can't stop GCC with LTO (done at link-time!) from assembling the last file, so what I did is use my GCC plugin to insert an .error and then .end at the very beginning of the file when it is generated.

GCC will error when it comes to this (final) assembly stage, but I filter out this error in my makefile. Then I simply remove the .error and .end and parse the asm with a script etc, then assemble it manually. Otherwise it's not possible to manually parse the final asm with LTO.

(btw yes, .error doesn't stop assembly, GAS is one of those "error avalanche" thingies, so it would parse it for no reason in my hack above, .end stops it immediately though)
Post 17 Jan 2018, 13:23
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 529
These symbol-less free-flowing end-comments IMO would allow more activity to the source.

Useful for;

1. Collaborative works (discussions, alternative codes etc)
2. Personal productivity (TO-DO list, reminder, notes, idea, thoughts etc)
3. Eliminate the need for some "include" files. For example, by placing all my "public" entries at the bottom, I can easily turn my executables into a DLL or an object file in an instant by moving them all at the top.
4. Pseudocodes, replacement codes and algorithms can be included in the sources more freely.

That would be awesome.
Post 17 Jan 2018, 14:01
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: 16057
Location: 112 Ocean Avenue, Amityville
Using the "macro" method is open to problems with a closing curly bracket within the comment. You can also use the assembler stage "if 0" / "end if", but that also breaks with certain embedded things in the comments.

Personally I use my editors ability to insert/remove bulk ";" characters before each line. It has the advantage of not having any negative character sequences and it displays the comments in the comment style (the colour and font change accordingly).
Post 17 Jan 2018, 14:06
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6968
Location: Kraków, Poland
Now that I think of it, "macro ?!" could perhaps be another feature of fasmg that might be back-ported to fasm 1.
Post 17 Jan 2018, 14:58
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: 16057
Location: 112 Ocean Avenue, Amityville
Block have been discussed here in the past, a few times.

I am in favour of some repeating characters for start/end
Code:
;...
<<<<< ;start the comment
Random comments go here
end if }}}}}} <--- these won't cause any problem
macro ignored {}
rept 999999999 {display 'blah'}
rb -1
err
mov al,0xFFFFFFFF
db "unfinished string
>>>>> ;finish the comment    
Of course this is still vulnerable to the sequence ">>>>>" appearing in the comment field.
Post 17 Jan 2018, 17:05
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1264
Maybe something similar to bash "here documents": http://tldp.org/LDP/abs/html/here-docs.html

Seems way overkill though. Confused
Post 17 Jan 2018, 21:38
View user's profile Send private message Reply with quote
yeohhs



Joined: 19 Jan 2004
Posts: 170
Location: N 5.43564° E 100.3091°
The truth is always in the code. Over-worked and tired programmers make changes to code but forget to change the comments. Sad

_________________
“It’s not that we have a short time to live, but that we waste a lot of it.”
-Lucius Annaeus Seneca
Post 17 Jan 2018, 23:39
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 529
revolution wrote:
Block have been discussed here in the past, a few times.

I am in favour of some repeating characters for start/end
Code:
;...
<<<<< ;start the comment
Random comments go here
end if }}}}}} <--- these won't cause any problem
macro ignored {}
rept 999999999 {display 'blah'}
rb -1
err
mov al,0xFFFFFFFF
db "unfinished string
>>>>> ;finish the comment    
Of course this is still vulnerable to the sequence ">>>>>" appearing in the comment field.
Something like so

The first code above was from Linux "gedit" and this one below is on Win32, using "fasmw" editors.
Code:
#
#  For Win32. Demo using GAS and CPULIB (cpu32.dll)
#  as this.asm -o this.obj --32
#  gcc -m32 this.obj cpu32.dll -o this.exe
#
        .code32             #force 32-bit code
        .globl _WinMain@16  #entry point for C

        .section .data
        .align 4
hello:  .asciz "Hello World\n"

        .section .text
_WinMain@16:
        push    %ebp
        mov     %esp,%ebp
        push    $hello
        call    _printf
        add     $4,%esp
        call    _dumpreg
        pop     %ebp
        ret
.end

Free-flowing notes:

        Manglish is the best English syntax in the world.
        come try lah!

        Basic skeleton for a 32-bit GAS on Win32
        mov <source>,<destination>
        No "db", "dw" etc. Sorry
        Registers come with % prefix. Ask Oracle for reference

        add esp,4 is CDECL stack cleanup and convention

        Can I just use .text instead of .section .text?
        I DON'T KNOW, ADRIANNNNN!!!

        int main()
        {
                printf("Hello World\n");
                return 0;
        }

        Equivalent Intel Syntax for "terrer" people
                push    ebp
                mov     ebp,esp
                push    hello
                call    _printf
                add     esp,4
                call    _dumpreg
                pop     ebp
                ret

output:
Hello World
EAX|0000000C EBX|00000001 ECX|76EBC620
EDX|77A36BF4 ESI|00890F30 EDI|00000007
EBP|0022FE98 ESP|0022FE98 EIP|00401580    


With this feature, imagine the level of expressions, information and 'dramatization' that can be injected into the otherwise a lifeless source. ;D
You don't have to worry about anything at all.
Post 18 Jan 2018, 00:21
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: 16057
Location: 112 Ocean Avenue, Amityville
fasmnewbie wrote:
You don't have to worry about anything at all.
It would be nice if the editor can recognise the comment correctly and render it like other comments. That way it is less likely a tired programmer will mistakenly think there is active code there and start to edit/debug/extend it.
Post 18 Jan 2018, 01:32
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2309
Location: Usono (aka, USA)
What you really want is a shar / shell archive (pure text). Unfortunately, I don't know of a perfect way to bootstrap such a thing for all platforms. I ended up using various tools (unshar, sed, AWK, REXX) on various OSes. For Windows, you'd probably be better off using VBscript or PowerShell or maybe even Javascript, dunno.
Post 07 Feb 2018, 20:16
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 529
revolution wrote:
fasmnewbie wrote:
You don't have to worry about anything at all.
It would be nice if the editor can recognise the comment correctly and render it like other comments. That way it is less likely a tired programmer will mistakenly think there is active code there and start to edit/debug/extend it.


is it difficult to ask the assembler to stop parsing / tokenizing a source or whatever it is called after like, ".stop" sign? In my cluless opinion, it's just a matter of text processing.

Something like so Razz

Code:
while not .stop or EOF or end-of-source
    keep assembling...
endwhile    
Post 14 Feb 2018, 00: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: 16057
Location: 112 Ocean Avenue, Amityville
fasmnewbie wrote:
is it difficult to ask the assembler to stop parsing / tokenizing a source or whatever it is called after like, ".stop" sign? In my cluless opinion, it's just a matter of text processing.
No, it is very easy to write the code.
Post 14 Feb 2018, 03:26
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-2018, Tomasz Grysztar.

Powered by rwasa.