-- helloworld.lasm .stacksize 2 .const "Hello, World!" -- constant is at index 0 .const "print" getglobal 0 1 -- load into register 0, the global with name from constant at index 1 ("print") loadk 1 0 -- load into register 1, the constant at constant index 0 ("Hello, World!") call 0 2 1 -- call the function at register 0, with 1 parameter, and keeping no returns.

For those of you that don't know, assembly languages are very nearly an exact representation of every byte in the bytecode. You will type out every instruction to the Lua VM.This simple LASM program prints the ever well known string "Hello, World!" First, we declare our constants. The order they're declared in determines the index they're at. So declaring constant "Hello, World!" puts it at index 0 (unlike Lua, the Lua VM usually works with 0 indexing). Then "print" is kept at constant index 1.Next, we use the "getglobal" instruction to load the "print" global into register 0. Next we use "loadk" to put "Hello, World!" into register 1. Finally, we call register 0 (print), with one parameter (register 1, the "Hello, World!"), and keeping no return values. For more info on "call," read the writeup posted above.So what are these "register" and "constant index" things? The Lua VM has four different stacks. The register stack, the constant stack, the upvalue stack, and the function prototype stack. The register stack is managed manually by the program. That's what .stacksize 2 is doing. It's telling Lua VM that we will be using no more registers than 2 (0, and 1). We don't have to use all the register we ask for, but we can't use more.The constant stack is automatic. As you declare constants they get added to the stack. This is managed at compile time, not runtime, so there's no modifying it.The upvalue stack is a stack that you can reference to get data from registers (or other upvalues) of the function prototype that you are a child of.The function prototype stack is pretty much the same as the constant stack, except the data held is the prototypes of functions. You see, when you declare a function in code, you're not writing magical function code to memory or anything. The bytecode has a special section where all your functions are written, and your code creates closures to use those functions (see closure instruction).