Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Ruby text editor, for Assembler code?

For general discussion related FlowStone

Ruby text editor, for Assembler code?

Postby HughBanton » Mon Jun 22, 2020 11:04 am

FS4 has a very much improved assem compiler, the text for which appears on the 'S' output of any DSP box. Here's a typical exerpt :
Code: Select all
// Comparison
movaps xmm0,rankSwitch;
cmpps xmm0,oldSwitch,6;

// '&' Operator
andps xmm0,_F_1;

// Assignment to 'reset'
movaps reset,xmm0;

// Comparison
movaps xmm0,rankSwitch;
cmpps xmm0,_F_1,1;

// '&' Operator
andps xmm0,_F_1;

// '+' Operator
addps xmm0,stageIn;

// Assignment to 'stage'
movaps stage,xmm0;

// Comparison
movaps xmm0,stage;
cmpps xmm0,_F_3,0;

// -> Cast operand to bool
xorps xmm1,xmm1;
cmpps xmm1,xmm0,4;

// Assignment to 'go'
movaps go,xmm1;

// Comparison
movaps xmm0,stage;
cmpps xmm0,_F_4,0;

// -> Cast operand to bool
xorps xmm1,xmm1;
cmpps xmm1,xmm0,4;

Really excellent for beginners, it practically tells you what every line does! (The 3.0.6 version is err .. more challenging).

However ... as you gain more knowledge you need ever-fewer comments; I sometimes end up with just the "// Assignment to ' .. ' " lines and remove 80% of the rest. But it can take a while, and it's very easy to make an annoying slip and have to start over ..

Any Ruby genius out there know how to automate some of this process? I feel sure there must be a Ruby text method. I'm thinking something where you can specify the lines you want to remove .. e.g. all the "// '+' Operator" lines, all the "// -> Cast operand to bool" lines. So that you customise it as you gain confidence.

Is it possible? Ta for any help - Ruby, and text in particular, not my forte I'm afraid!

H
User avatar
HughBanton
 
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Re: Ruby text editor, for Assembler code?

Postby deraudrl » Mon Jun 22, 2020 4:41 pm

My first question is, "Why?"

If I'm reading this correctly, what you're doing is generating "raw" assembly code using a DSP component, presumably with the intent to hand-optimize it for use in an ASM component.

Seems like it would be easier to just grab the whole 'S' output, paste it into a real (non-FS) code editor, do your edits, and then paste it into an ASM component in one lump. Using what amounts to a raw Windows TextBox widget to edit code sounds too much like putting together a car engine with nothing but an adjustable spanner. Not to mention that you can keep the resulting code snippets somewhere safe for re-use.
I keep a pair of oven mitts next to my computer so I don't get a concussion from slapping my forehead while I'm reading the responses to my questions.
deraudrl
 
Posts: 239
Joined: Thu Nov 28, 2019 9:12 pm
Location: SoCal

Re: Ruby text editor, for Assembler code?

Postby HughBanton » Mon Jun 22, 2020 5:00 pm

Well, grabbing the whole thing and copying to Assem box, then editing to suit, is the standard method. But there's always the risk of screwing up mid-way of course.

And since I always spend time removing the more 'obvious' comments I wondered if some of it could be streamlined, just to save time.

I've discovered 'gsub' today in Ruby, which gets me part-way there. Just need to find out how to remove all the white space it leaves behind.

Ruby Assem code cleaner.fsm
(1.18 KiB) Downloaded 919 times

H
User avatar
HughBanton
 
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Re: Ruby text editor, for Assembler code?

Postby HughBanton » Mon Jun 22, 2020 6:24 pm

I've added a text box to indicate what I'd optimally like to end up with - this is the max pruned version. (.. Prior to any manual code optimising obviously, once it's copied into Assem).

The individual gsub lines in Ruby can be #'d to bypass them, so editing which type of comments you want to see, and which you don't, would be dead easy. Although I dare say this can be made a bit more pro.

Personally I like to keep "//Assignment to '...' " in this manner, with the gap after each block, because this neatly splits the assembly code up to exactly reflect what was in the original DSP. i.e. each block of Assem = one DSP statement. Makes it easier to follow. (That's something 3.0.6 already does do ..) It'll need a bit of Ruby fiddling, I think, to retain this gap but remove all others.

Your Ruby challenge starts now ... ;)

Ruby Assem code cleaner_2.fsm
(1.42 KiB) Downloaded 895 times

H
User avatar
HughBanton
 
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Re: Ruby text editor, for Assembler code?

Postby wlangfor@uoguelph.ca » Mon Jun 22, 2020 6:36 pm

Cool, I'll check it out :)
My youtube channel: DSPplug
My Websites: www.dspplug.com KVRaudio flowstone products
User avatar
wlangfor@uoguelph.ca
 
Posts: 912
Joined: Tue Apr 03, 2018 5:50 pm
Location: North Bay, Ontario, Canada

Re: Ruby text editor, for Assembler code?

Postby trogluddite » Mon Jun 22, 2020 9:31 pm

Code: Select all
result    = ""
is_assign = false

@text.each_line do |line|

  # Skip all-whitespace lines.
  next if line =~ /^\s*$/
 
  # Check for assign comments.
  if line.start_with?("// Assignment")
    result << line
    is_assign = true
    next
  end
 
  # Skip ahead if comment line.
  next if line.start_with?("//")
 
  # Append the line of code.
  result << line
 
  # Extra line feed after assignments.
  if is_assign
    result << "\r\n"
    is_assign = false
  end

end # each_line

output result
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Ruby text editor, for Assembler code?

Postby MichaelBenjamin » Tue Jun 23, 2020 12:44 am

.
Last edited by MichaelBenjamin on Mon Sep 21, 2020 10:53 am, edited 1 time in total.
MichaelBenjamin
 
Posts: 275
Joined: Tue Jul 13, 2010 1:32 pm

Re: Ruby text editor, for Assembler code?

Postby trogluddite » Tue Jun 23, 2020 8:03 am

MichaelBenjamin wrote:nice and readable, but this line sticks out:

# Skip all-whitespace lines.
next if line =~ /^\s*$/

is that some regex stuff? it could need some explanation on its usability vs readability esp. for ruby newbies.

isn't there a syntax like:
next if line.length()==0

Its a regular expression yes - a habitual usage because it's so useful. The lines won't be zero length as the line endings aren't stripped off by 'each_line', and Ruby line endings can be a bit weird in FS (sometimes Windows, sometimes Unix). "Any whitespace" saved me having to know exactly what I was testing for!

As for explaining the Regex - wooo, that's a deep rabbit hole - I'll just stick with saying it's "magic" for now!
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Ruby text editor, for Assembler code?

Postby tulamide » Tue Jun 23, 2020 8:30 am

Michael, visit ruby-doc.org, it will explain the regex class in all details. I would normally link to the correct page, but ruby-doc.org is currently unavailable.

This is also a nice online tool to test your regex before coding it.
https://rubular.com/

In this specific case, I think, it is only the weird signs and charcter combination that's a bit intimidating. But the regex just says "if the line between start and end of line only contains any whitespace characters or is empty".
^ = start of line
\s = any whitespace character
* = zero or more occurences of former regular
$ = end of line
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Ruby text editor, for Assembler code?

Postby HughBanton » Tue Jun 23, 2020 9:42 am

Astounding, trog, bullseye. (Wish I could do that!). This will make a really useful utility for those of us who habitually write things in DSP and later need a quick Assem-code first edit.

You won't be surprised to hear I have a candidate already lined up, which gave me the idea yesterday. 10 minutes saved already.

I was going to put together a full demo, DSP right through to Assem, but of course the 3.0.6 commenting doesn't look anything like this so wouldn't work here. I'll do something over on Slack later.

Many many thanks :D

H
User avatar
HughBanton
 
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Next

Return to General

Who is online

Users browsing this forum: Google [Bot] and 16 guests