flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > interesting tweak

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 28 Jul 2004, 10:09
Very simple to do, just open ASSEMBLE.INC file and find the "instruction_assembled" label (around the line 324), and then instruction
Code:
        jnz     extra_characters_on_line    

5 lines below that label.
By changing this instruction to:
Code:
        jnz     assemble_line    

you will get tweaked fasm version, which will accept such an awful multi-instruction lines like this:
Code:
mov eax,0 inc ebx mov eax,[ebx] org 700h mov eax,$    
Post 28 Jul 2004, 10:09
View user's profile Send private message Visit poster's website Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 28 Jul 2004, 10:43
Very cool -- now it's pretty close to the syntax I'm using in the assembler I'm writing for use with RetroForth Smile
Post 28 Jul 2004, 10:43
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 28 Jul 2004, 10:59
awesome!

--
PS: In VIM, you can change it like this.
debian:~/fasm/source# vi assemble.inc
:329s/extra_characters_on_line/assemble_line
:wq
debian:~/fasm/source# _
Post 28 Jul 2004, 10:59
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 28 Jul 2004, 12:05
Any chance of being able to use macros with this? I use a bunch of macros that don't take arguments and would love to be able to string them together with assembly code Smile
Post 28 Jul 2004, 12:05
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 28 Jul 2004, 17:06
I'm afraid preprocessor cannot be tweaked so simply.
Post 28 Jul 2004, 17:06
View user's profile Send private message Visit poster's website Reply with quote
Joshua



Joined: 12 Jul 2003
Posts: 56
Location: Belgium
Joshua 28 Jul 2004, 17:31
Well if you could get this to work on preprocessor too, it would solve our multiline fix problem!

Thanks, and keep at it...

PS i hope this tweak (and the preproccor part) can make it in the official version, although i still think a specific character for allowing this would be better
Post 28 Jul 2004, 17:31
View user's profile Send private message Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 28 Jul 2004, 17:35
I agree Joshua...
Post 28 Jul 2004, 17:35
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 28 Jul 2004, 18:19
I'm not going to include it in official releases, too confusing trick. That's why I only posted it here as a kind of curiosity.

But for your problem Joshua, here's another, a bit more complex modification, which I may include in next official version.

All modifications have to be made in PREPROCE.INC

1) find "preprocess_line" label (line 248), after:
Code:
        push    [struc_name]
        push    ecx esi    

put new label:
Code:
      preprocess_current_line:    


2) find "skip_macro_block" label (line 960), before the "skip_macro_symbol" you have the instructions:
Code:
        lods    byte [esi]
        or      al,al
        jnz     extra_characters_on_line
        and     [macro_status],0F0h
        jmp     line_preprocessed    

Change them to:
Code:
        and     [macro_status],0F0h
        lods    byte [esi]
        or      al,al
        jz      line_preprocessed
        dec     esi
        mov     ecx,edi
        sub     ecx,esi
        lea     esi,[esi+ecx-1]
        lea     edi,[edi+1+16]
        mov     ebx,edi
        dec     edi
        std
        rep     movs byte [edi],[esi]
        cld
        sub     edi,16-1
        mov     byte [edi-1],0
        mov     esi,[current_line]
        mov     [current_line],edi
        mov     ecx,4
        rep     movs dword [edi],[esi]
        mov     edi,ebx
        jmp     preprocess_current_line
      skip_macro_symbol:
        movzx   eax,byte [esi]
        inc     esi
        add     esi,eax
        jmp     skip_macro_block
      skip_macro_string:
        lods    dword [esi]
        add     esi,eax
        jmp     skip_macro_block    


This allows putting any instruction or directive in the line after the } symbol ending macro definition.
Example of possible usage:

Code:
macro struct name
 {
   common
   name@struct fix name
   struc name {
 }

macro struct_helper name
 {
   virtual at 0
   name name
   sizeof.#name = $ - name
   name equ sizeof.#name
   end virtual
 }

ends fix } struct_helper name@struct

; And now some nice definition:

struct RECT
   .left   dd ?
   .top    dd ?
   .right  dd ?
   .bottom dd ?
ends    
Post 28 Jul 2004, 18:19
View user's profile Send private message Visit poster's website Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 28 Jul 2004, 23:23
Quote:
I'm not going to include it in official releases, too confusing trick. That's why I only posted it here as a kind of curiosity.


I can understand that. Even so, I think I'll keep the hack in my copy of FASM Smile
Post 28 Jul 2004, 23:23
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 29 Jul 2004, 09:53
Question to everyone: would you want/accept this second change (allowing instructions/directives after macro ending character) in official releases?
Post 29 Jul 2004, 09:53
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 29 Jul 2004, 10:08
Of course, as it would make FASM preprocessor more powerful Wink
Post 29 Jul 2004, 10:08
View user's profile Send private message Visit poster's website Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 29 Jul 2004, 10:22
Yes! That would be great, Privalov! Wink
Post 29 Jul 2004, 10:22
View user's profile Send private message Visit poster's website Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 29 Jul 2004, 10:49
Sure, keep the second change in the official releases. It doesn't hurt anything from what I've seen, and actually makes some things easier
Post 29 Jul 2004, 10:49
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 29 Jul 2004, 11:27
OK, I will also replace the "struct" macro in the standard includes with this version - it makes the includes much more elegant.
Post 29 Jul 2004, 11:27
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 29 Jul 2004, 12:57
One side-effect of this feature is that you can define multiple macros in the same line, like:
Code:
macro alpha {db 1} macro beta {db 2} macro gamma {db 3}    
Post 29 Jul 2004, 12:57
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 29 Jul 2004, 13:03
Very good!
Even the first tweak could be in the official release as long as it didn't become an habit to write such kind of code.
In other words, compiler has the power but programmers the good sense to write readable code, given that even without the tweax exist the possibility to write obfuscated code Smile
Post 29 Jul 2004, 13:03
View user's profile Send private message Yahoo Messenger Reply with quote
Imagist



Joined: 13 Jun 2004
Posts: 114
Location: Pennsylvania (USA)
Imagist 29 Jul 2004, 14:49
If bad programmers start abusing the powers you add to FASM, you can just remove the changes from the next version of FASM. Very Happy

Ugh, I can't imagine the horror of wading through a FASM program written on one line. I've done it with a C program that had been reverse compiled and posted on a site (the guy's program wasn't programmed to add white space) and that was miserable, but at least then I had semicolons to tell me where the statements ended.

I like FASM the way it is. There's no point adding stuff that no good programmer will ever use. But it's like I said, if it becomes a problem you can always take it out.
Post 29 Jul 2004, 14:49
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 29 Jul 2004, 18:23
i like second one (commands behind "}"), unless it little bit "unsyntactical" it solves few problems so it's OK.
First one, of course, no.
Post 29 Jul 2004, 18:23
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 29 Jul 2004, 18:32
vid: so we agree.
Post 29 Jul 2004, 18:32
View user's profile Send private message Visit poster's website Reply with quote
Joshua



Joined: 12 Jul 2003
Posts: 56
Location: Belgium
Joshua 29 Jul 2004, 18:35
Thanks priv! This is all i needed...

Now for the next question: When will the new official fasm version (with this feature in it) be released? Wink
Post 29 Jul 2004, 18:35
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.