flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > [RISC-V] several real instructions per line.

Author
Thread Post new topic Reply to topic
sylware



Joined: 23 Oct 2020
Posts: 441
Location: Marseille/France
sylware 29 Mar 2023, 11:47
I was reading a bit the RISC-V specs and many common operations are actually sets of a few instructions.

This is expected for a 'R'educed instruction set.

But, I would like to avoid to write an assembler macro for each of those common operations... and their variants!

That's why it seems somewhat critical the assembler handles multiple instructions per source file line.

Hence, I wonder about the impact of this modification on fasmg specs and implementation.
Post 29 Mar 2023, 11:47
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4046
Location: vpcmpistri
bitRAKE 29 Mar 2023, 15:14
What does it look like? Is there an instruction separator? Couldn't instructions just forward any unprocessed text as another instruction?

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 29 Mar 2023, 15:14
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 29 Mar 2023, 18:39
writing macros is not so hard. in fact, with fasmg, everything is macro, then...
Post 29 Mar 2023, 18:39
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: 20355
Location: In your JS exploiting you and your system
revolution 29 Mar 2023, 23:56
Three instructions on a single line:
Code:
irp i, <mov ax, bx>, <cmp cx, dx>, <imul ebx, ecx, 42> {i}    
To me it looks unclear and confusing. But maybe others see it as some kind of new awesomeness?
Post 29 Mar 2023, 23:56
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1635
Location: Toronto, Canada
AsmGuru62 30 Mar 2023, 00:22
Confusing for me as well.
Post 30 Mar 2023, 00:22
View user's profile Send private message Send e-mail Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4046
Location: vpcmpistri
bitRAKE 30 Mar 2023, 00:34
Well, in the past we've seen many attempts at compact code:
Code:
imul ebx, <cmovc <cmp ecx, eax>, edx>, 42 ; destination falls out of <>    
... in time certainly patterns become familiar, but it seems to loose flexibility? Some people try to side-step the mnemonics using symbols, others rename the registers, ... basically, just trying to personalize the look or obfuscate the code, imho.

That's why I was curious what kind of syntax is being suggested by the RISC-V spec. Maybe they found something that works, or perhaps the ops are so miniscule as to work like instruction prefixes?

* RoAsm using | as a line break for multi-instruction lines.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup


Last edited by bitRAKE on 30 Mar 2023, 00:45; edited 1 time in total
Post 30 Mar 2023, 00:34
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: 20355
Location: In your JS exploiting you and your system
revolution 30 Mar 2023, 00:43
bitRAKE wrote:
That's why I was curious what kind of syntax is being suggested by the RISC-V spec. Maybe they found something that works, or perhaps the ops are so miniscule as to work like instruction prefixes?
It isn't a spec of RISC-V. It is a suggestion by sylware.

The RISC-V instruction mnemonics are perfectly normal.
Post 30 Mar 2023, 00:43
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: 20355
Location: In your JS exploiting you and your system
revolution 30 Mar 2023, 02:41
bitRAKE wrote:
* RoAsm using | as a line break for multi-instruction lines.
| is logical or for fasm.

Perhaps using \ could work? Usually \ is for line concatenation, but if followed by more text then it could also serve as a line break.
Code:
inc ax \ cmp ax, 42 \ seta cl    
Post 30 Mar 2023, 02:41
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4046
Location: vpcmpistri
bitRAKE 30 Mar 2023, 04:58
For fasmg there aren't many limitations for what can be used. Even semicolon is possible.
Code:
inc ax ; cmp ax, 42 ; seta cl    

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 30 Mar 2023, 04:58
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 30 Mar 2023, 07:49
And do you remember that simple tweak of fasm 1?
Post 30 Mar 2023, 07:49
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 441
Location: Marseille/France
sylware 30 Mar 2023, 09:32
Well, I was expecting some clear-cut and well defined way to get a "real instruction" separator on a line for fasmg (in x86_64, that would be ';' I guess).

Since one of the major RISC-V assembler is binutils as, the instruction separator on line would be ';'.

For instance, RIP relative addressing on RISC-V is a set of dual instruction combos. Since I would like to keep the real instructions and not define 73894739847394 macros or some massively parameterized macros, I would write those combos on a single line.

label: instruction ; label: instruction ...

EDIT: (basically a real token from a set of real tokens).
Post 30 Mar 2023, 09:32
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 30 Mar 2023, 12:24
As bitRAKE pointed out, fasmg gives you much freedom to decide what syntax you're going to use:
Code:
calminstruction ? line&
        local instruction
    loop:
        match instruction | line, line
        jno final
        assemble instruction
        jump loop
    final:
        assemble line
end calminstruction

inc ax | here: cmp ax, 42 | seta cl    
...and as mentioned by bitRAKE too, even semicolon could be used:
Code:
retaincomments

calminstruction ? line&
        local instruction, comment
        match line // comment, line
    loop:
        match instruction; line, line
        jno final
        assemble instruction
        jump loop
    final:
        assemble line
end calminstruction

inc ax ; here: cmp ax, 42 ; seta cl // comment    
Post 30 Mar 2023, 12:24
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 441
Location: Marseille/France
sylware 30 Mar 2023, 14:16
Allright, I stand corrected, there is no interference of using ';' as an instruction separator on a line.

Hard for an occasional fasmg macro/calm coder like me to forget not about the "for each line" preprocessing...

Actually I may add this to my existing x86_64 fasmg code to allow "one liner" C preprocessor macro, like I have with the binutils as support C preprocessor macros.

Now and as far as I know, the bad apples seem to be nasm/yasm where there is no multi-instruction line (I will probably drop them once I start to code some RISC-V assembly then).

meh.
Post 30 Mar 2023, 14:16
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


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.