Have any of you tried the WebAssembly? I think that could be another interesting area where fasmg could become useful. After I finish the AVX-512 macros I'm working on currently I might give it a try and write some WebAssembly macros. Or perhaps someone already tried it?

At first i never even heard of it, but it got me curious and i have a (very simple/small) example working.
I used this page as a source : https://medium.com/@MadsSejersen/webassembly-the-missing-tutorial-95f8580b08ba
To enable it in firefox you need to go to about:config and enable "javascript.options.wasm" and then restart your browser.
I think you should remember to disable it again once you're done testing/playing, since it's still experimental.

Two ways you can use this :
1. In a html page, see test.html in attached archive
2. paste the text i output with display (test.asm) in the webconsole commandline

The single macro "section" in webasm.inc only captures the generation of the textlength/name/rest of section length, but it's a start i guess
The defined function name is 'sum' and takes two i32 parameters and returns one i32

I believe that we can make some good macros packages for fasmg that would assemble these structures and instructions with a clean syntax. But I have to say that I am not very excited with this architecture.

I admit that I simply dislike stack-based architectures in general, including the x86 FPU. I feel that for anything more complex than the very basic snippets you need to carefully trace the contents of the stack at any point in code and you end up writing comments about what is on the stack after every instruction. But at the same time it allows to make the binary code more compact, so I understand why it is a tempting option.

However even Java byte-code, which is also stack-based, at least has some classic branching instructions (like conditional jumps). You cannot utilize their power to the full extent because of some arbitrary rules for the code structure enforced by JVM (which are perhaps the main reason why I gave up trying to write anything for JVM in an assembly-like language), but still they are there. And in WebAssembly the branching instructions look like "if", "else" and "end", structuring the code in blocks. I think that someone must have read too much into Dijkstra's pet-peeve. I am pretty convinced that this approach does not lead to more compact code - I have recently demonstrated that modern compilers are able to make a really good use of jump instructions to generate an efficient code, and hand-crafted assembly has always been full of similar tricks.

Not that I think that instructions like "if" are necessarily a bad idea - I think we could perceive them as a tool similar to conditional predicates of ARM (or their less robust kin in x86 architecture - CMOV), with the difference that they could apply to entire blocks of instructions instead of a single one (though I'm not sure if this could be as effective in terms of efficiency). But I do believe that any assembly language without jump instructions is deeply flawed.

In the browser I use (Vivaldi) the expected WebAssembly version was 13, so I had to convert your sample to a new format. And while I was at it, I tried to make macros that would provide a bit of automation. The rewritten sample looks simply like this:

You can add more functions and the structures should be assembled correctly. It does not detect if two or more function have the same signature in order to "compress" the type section, I though it was not important enough to warrant making the macros more complex. And it does not allow to declare additional local variables, though it should be easy to add - I just did not have an idea for a syntax.

Oh, and not all instructions are supported. I only made macros for some of them, the ones I needed for testing.

I have made an improved version of these macros which do not generate multiple type entries for the same function signature, because I wanted to test a simple trick that I devised for this purpose. And at the same time I added basic support for local variables (with "var" macro inside the function body) and allowed alternate syntax "i32 x" in place of "x:i32" (both variants are allowed, it does not increase the complexity of macros, choosing to use just one variant would only make them a little bit shorter).

The "var" macro outside of the function bodies could be made to generate global symbol entries and the instruction set is left only partially implemented, but I feel that my enthusiasm here burns out very quickly.

First off, wow you got working what i could not, i was still messing around with version 11, which doesn't make much sense anymore.
These look a lot better and complete than what i have, so i'll use these as a basis.
I plan to do my best to implement as much as i can, as a learning experience, if it's anything worthy i'll post it as an example for anyone who cares.
I'm not very proficient with the complete macro language (yet), so this is a good challenge (started now with a way to import javascript functions).

Thanks again for these examples.

By the way, couple of days ago i needed to unwatch and then rewatch the topic as i did not receive any updates from it, does that happens sometimes ?

Have any of you tried the WebAssembly? I think that could be another interesting area where fasmg could become useful. After I finish the AVX-512 macros I'm working on currently I might give it a try and write some WebAssembly macros. Or perhaps someone already tried it?

This is a good use for fasmg, and your quick examples are impressive.

Tomasz Grysztar wrote:

... But I do believe that any assembly language without jump instructions is deeply flawed.

Well, yes, strictly I'd agree, but WebAssembly looks to be an 'assembly language' only in the loosest sense.

That's why I referred to the fact that modern compilers are able to put branches into a very good use, so even when the instruction set is only going to be used by high-level compilers, having traditional branches may still be beneficial.

But I understand that this is in fact an "intermediate" language, a half-compiled stage that is going to be further compiled when the WebAssembly module is loaded for execution. Though I think that splitting compilation in half like that may make some types of optimization less effective.

That's why I referred to the fact that modern compilers are able to put branches into a very good use, so even when the instruction set is only going to be used by high-level compilers, having traditional branches may still be beneficial..

Maybe they will add jump instructions in some form, tho I imagine they could be security cautious here ?

Jump instructions would be useful, on embedded controller versions of this.

You are right on the website of this assembler, please visit the Download section (the link is also available in the shortcut menu on the bottom of message board page) and look for the "flat assembler g" package.

jorido wrote:

Has anyone been able to get it to work? I have 2 errors: (...)

You need to upload the files to a server to get this to work. Also note that the all the output generated by the example goes to JS console.

As for WebAssembly example, the standard has since moved from pre-MVP version numbering to a more official MVP 1.0 release. Because of that, the above example causes this error:

So I changed the version number field in the header to 1 and the sample seems to work correctly. I attach the updated example below.

Also, please keep in mind that this was quickly patched-up and I have not implemented the complete instruction set. But writing the instruction macros (placed in the WASMCODE.INC) is a very simple task. And if this generates any attention I may implement more instructions and include this in the official fasmg package.

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum