Learn GASM

Welcome to GASM's learning page!
Here you will find tutorials to get you started immediately.
This tutorial is most useful to programmers with experience of basic programming concepts and familiarity with assembly code & syntax – especially the Intel x86 assembly.

Well, open up the Console or the Playground in another tab and let's get started!

Hello Line!

Whilst with most languages, the first program you've ever learned to write in them must've been the classic "Hello World" program – but with GASM, being a graphical language itself, we will be writing something rather different for our first project: a "Hello Line" program.

So, let's see what it looks like:

``` ; My first Hello Line program! movp 0, 0 line -1, -1 ```

Well, how about that? Only 3 lines of code!
And if everything worked out alright, you should see the following output:  In order to draw a line with GASM, we need to do three things:

  1. Set the position of the point where the line starts.
  2. Set the position of the point where the line ends.
  3. Draw the line.

Simple, right? Well, that's exactly what the code above does.
In each line of the code, two parts could be found:

So, let's take a look at what each line does:

Notice how we've given it negative coordinates? They certainly don't mean drawing outside of the canvas, of course – they are called inverse offsets, meaning that their real position is calculated by the size of canvas minus their absolute value;
Therefore, in the example given above, us passing the coordinate ` -1, -1 ` to `line` is literally shorthand for: ``` line [i] <<the width of the canvas>> </i> - 1, <i> <<the height of the canvas>> [/i] - 1 ``` Do mind that the above code is a piece of pseudocode – calculations are not done like so in GASM!

Now, you may ask: if so, then could I have `-0, -0`?

Well, I can tell you the answer now: definitely! In GASM, the '−' sign does not mean that the number is negative; it simply means that the numeric value is an offset. Therefore, unlike zero and negative zero, `0` and `-0` in GASM represents completely different values, and you could, indeed, have statements like `line -0, -0`.
In fact, why don't you try it out now?

Comments

You must've noticed something different in the first line: it starts with a semicolon ` ;  `, and it doesn't look like a piece of code; in fact, it's a sentence – a human-readable, English sentence.

What does it do? What could possibly be its function?

A simple and minimalistic answer would be: nothing.

Well, nothing to do with the program itself, anyway.
If you remove that line, the program's output will be exactly the same.
Lines that contain or start with a semicolon are called comments – for example, ``` ; This is a comment. ``` The content inside the comments is completely ignored by the GASM processor, which, in this case, is JS-GASM's HTML5 & Javascript interpreter, which is used in the Playground and the Console.

Therefore, the comment is not intended to be read by the machines, but by us, the humans. It is invented to make the source code more understandable, and store extra information about parts of the code.
So even though this is a piece of legal code, it really does not help the readers much: ``` line -5, -5 ; VXNlbGVzcyBDb21tZW50! AsdfG h JKlZ xcVb Nm ~!@#$%&*()_+ ```

Variables

Variables are one of the most important features of the GASM programming language!
It's declared and assigned like so: ``` set $.[i]<<optional.variable.namespace>>[/i][span class="gasm-variable"].variable_name[/span] <<initial_value>> ``` and are referenced like this: ``` line $.var1, $.var2 ; using their values ``` All variables are global, and will exist until the program ends, or explicitly deleted with the `del $.variable_name` instruction.



Now that you have learned the most basic features of GASM, go and check out the GASM Reference for more detailed information and more advanced features such as functions and debugging.