flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasmg] Octal numbers by default, directives with leading .?

Author
Thread Post new topic Reply to topic
TimUr



Joined: 09 Sep 2024
Posts: 2
TimUr 09 Sep 2024, 11:53
Hello everyone!
Tell me, please, is it possible to make FASMg interprets all numbers without suffixes and prefixes as octal?
And numbers with '.' at the end will be interpreted as decimal?
And is it way to make FASMg to parse directives with leading dot?
Example:
Code:
ORG 3000           ; org 600h
ST:
    MOV   #10.,R0  ; R0 = 10
    MOV   #32, R2  ; R2 = 32o
    MOV   PC,R1
    ADD   (PC)+,R1
    .WORD @END+2
END:
    .END

.WORD 177777       ; dw 0FFFFh
.BYTE 10           ; db 8
    
Post 09 Sep 2024, 11:53
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4175
Location: vpcmpistri
bitRAKE 09 Sep 2024, 12:46
Leading dot can be captured:
Code:
calminstruction ? line&
        match =.any,line
        jyes directive
;       assemble line ; forward
        stringify line
        display line
        display 10
        exit
directive:
        stringify line
        display 9
        display "DIRECTIVE: "
        display line
        display 10
end calminstruction    
... normally, non-dot lines would be forwarded for other processing. Trailing dots should be parsable in a similar manner, "match any=.,item".

There is no automatic way to interpret numbers as octal - it would require parsing and base conversion from decimal to octal, or character by character conversion. It is possible though.
Post 09 Sep 2024, 12:46
View user's profile Send private message Visit poster's website Reply with quote
TimUr



Joined: 09 Sep 2024
Posts: 2
TimUr 09 Sep 2024, 12:54
bitRAKE wrote:
Leading dot can be captured:
...
normally, non-dot lines would be forwarded for other processing. Trailing dots should be parsable in a similar manner, "match any=.,item".

There is no automatic way to interpret numbers as octal - it would require parsing and base conversion from decimal to octal, or character by character conversion. It is possible though.

Thanks! Good example.
Post 09 Sep 2024, 12:54
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4175
Location: vpcmpistri
bitRAKE 09 Sep 2024, 13:00
There is some nuance: for example, you could allow spaces between the dot and the directive by changing the match: "match =. any,line" -- putting a space after the dot. It all depends on the language you want to support.
Post 09 Sep 2024, 13:00
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: 20526
Location: In your JS exploiting you and your system
revolution 09 Sep 2024, 13:04
bitRAKE wrote:
There is no automatic way to interpret numbers as octal - it would require parsing and base conversion from decimal to octal, or character by character conversion. It is possible though.
Does fasmg use the o suffix for octal? Couldn't it add a trailing o if no other suffix is present, then let the engine do the conversion?
Post 09 Sep 2024, 13:04
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4175
Location: vpcmpistri
bitRAKE 09 Sep 2024, 13:15
revolution wrote:
Couldn't it add a trailing o if no other suffix is present, then let the engine do the conversion?
That would probably be the best technique once the parsing determined it was a number. There is an added complication in that determining the number type would also support a conversion - it's doubtful that will be a problem though. If the user mistakenly had some other number decoration it'd most likely be a syntax error, or pruned prior.

Edit: I'm just being extremely pedantic and making no assumption about the target language. The match directive can't disambiguate number forms (ex. $00, 0x00, 00o, 0_0b), and fasm[g]'s number forms are more advanced than most languages.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 09 Sep 2024, 13:15
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 09 Sep 2024, 17:02
bitRAKE wrote:
Leading dot can be captured:
Code:
calminstruction ? line&    
I would recommend using the new "??" interceptor instead, it could catch the dotted directive when it is otherwise unrecognized, with a side effect that it would also allow it to be overridden by a dot-local macro, but normally that should not be an issue. And "??" interceptor does not affect the performance of assembly like "?" one does.

As for the custom number formats, there's been this old example: https://board.flatassembler.net/topic.php?p=190479#190479
Certainly could be improved with CALM.
Post 09 Sep 2024, 17:02
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4175
Location: vpcmpistri
bitRAKE 09 Sep 2024, 19:28
This will allow END: label:
Code:
calminstruction END line& ; allow partial directive label
        local any
        arrange any,
        match :any?,line
        jyes label
        arrange line,=END line
        assemble line
        exit

label:  arrange line,=label =END
        assemble line
        assemble any
end calminstruction    
... perhaps there is a better way. Seems like a case-insensitive version would require a different approach.
Code:
macro ? line&
        match =END? : rest, line
                match lead : rest, line
                        label lead
                        rest
                end match
        else match =END? :, line
                match lead :, line
                        label lead
                end match
        else
                line
        end match
end macro    
... or with calm:
Code:
calminstruction ? line&
        local rest
        arrange rest,
        match =END? : rest?,line
        jyes label
        assemble line ; forward
        exit

label:  match lead : rest?,line
        arrange line,=label lead
        assemble line
        assemble rest
end calminstruction    
... always in awe at the flexibility that calm has become.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 09 Sep 2024, 19:28
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 10 Sep 2024, 09:50
bitRAKE wrote:
... perhaps there is a better way.
The standard solution (that I also mentioned in my fasm2 video) is to force the label with a "?" modifier:
Code:
?END:    

And there is also the old detached namespace trick that allows to reclaim all the keywords.
Post 10 Sep 2024, 09:50
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.