Author Topic: Maximum Over Drive System - Lua Assembly Toolkit  (Read 12380 times)

0 Members and 1 Guest are viewing this topic.

Offline pianoman

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 426
  • Rating: +24/-0
  • ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫
    • View Profile
Re: Maximum Over Drive System - Lua Assembly Toolkit
« Reply #15 on: August 22, 2011, 11:22:20 am »
I'm sorry about all of the questions, but I'm still just a bit confused D:
Which file/folder would we make the example script you showed above in?
Then, once we do that, which script do we run to convert to bytecode?
And, finally, (yes, I know this will sound stupid) how do we run Lua scripts like that on the computer?
Thank you very much!

EDIT: Any chance you could make some sort of an API/less confusing and nspire-oriented tutorial? :w00t:
« Last Edit: August 22, 2011, 12:24:31 pm by pianoman »

Offline NecroBumpist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 130
  • Rating: +14/-5
  • Master of Lua
    • View Profile
Re: Maximum Over Drive System - Lua Assembly Toolkit
« Reply #16 on: August 22, 2011, 06:56:42 pm »
pianoman, I'm dearly sorry. I really have been neglecting properly documenting everything. I'll get working on that after I answer your questions :P

Which file/folder would we make the example script you showed above in?
Then, once we do that, which script do we run to convert to bytecode?
You could run it in the \src\ folder I believe.
The script you would use to convert it is the "current.lua" one.

So you would first have to require() that, (sort of like #include)

Code: (Lua) [Select]
-- let's assume this script is in the \src\ folder
local mods = require("current"); -- this runs current.lua, which returns a table of the major API functions

local bytecode = mods.Assemble([[

; put cool bytecode here

]]); -- this passes the multi-line string argument to Assemble(), which turns it into bytecode
-- The easiest way to utilize bytecode in a script is in an escape sequence like so: \104\101\108\108\111  (this is the ASCII sequence "hello")
print(bytecode:gsub(".", function(a) return "\\" .. a:byte() end)) -- this is the bytecode in the above format, which you can pass as a string argument to loadstring()

And, finally,  how do we run Lua scripts like that on the computer?
You would need the Lua executables:
  • For Linux: Download the source code and compile or find the proper package to install
  • For Windows: Download LuaForWindows


Any chance you could make some sort of an API/less confusing and nspire-oriented tutorial?

Yes :)
I will also add command line support so you can do the following:
Code: (cmd.exe) [Select]
>lua current.lua input.lasm -o output.lua
Which will create a .lua file that will loadstring() an ASCII sequence like I demonstrated above :)

Also, thanks ExtendeD  ;D
Developing Lua scripts for the NSpire ?
Check out the Necrotorium
Need a few routines to run faster ? Checkout the MODS Lua Assembly Toolkit.
Need to save space for your scripts ? Checkout LuaSrcDiet

Offline pianoman

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 426
  • Rating: +24/-0
  • ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫
    • View Profile
Re: Maximum Over Drive System - Lua Assembly Toolkit
« Reply #17 on: August 22, 2011, 09:41:49 pm »
Nonono, NecroBumpist. You of all people have nothing to apologize for. If anything, I should be apologizing for asking so many questions and asking for so much so soon.
Thank you very much for your swift reply, and I can't wait to use all the cool things LASM can help us with :)

Ashbad

  • Guest
Re: Maximum Over Drive System - Lua Assembly Toolkit
« Reply #18 on: August 29, 2011, 09:40:24 am »
This reminds me of the Sharp Assembly Suite that Harold made on cemetech a while back ( http://www.cemetech.net/forum/viewtopic.php?t=6355&postdays=0&postorder=asc&start=0 )

While it is different because it's intended for only one platform, some of the same questions Kllrnohj and others brought up remain, but concerning this "assembler" instead: assembling on the fly (which the does) will be quite slow, when usually Lua code when written well is going to be very optimized.  Won't the speed loss pretty much make this rather trivial, unless you re-use a certain Lua Bytecode module many many times (and the module actually holds optimized code)?  Would it not be better to build a separate "assembler" not built into a script using this technique that compiles some Lua IR into byte code that could be copy-pasta'd into a loadstring() call?

Just my 2 cents

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Maximum Over Drive System - Lua Assembly Toolkit
« Reply #19 on: August 30, 2011, 03:03:18 am »
The fun part on loadstring is that it return a function, which you will be able to use during the whole script. So if you do everything in the beginning (when you open the script), it should be fine :)

Ashbad

  • Guest
Re: Maximum Over Drive System - Lua Assembly Toolkit
« Reply #20 on: August 30, 2011, 11:21:28 am »
The fun part on loadstring is that it return a function, which you will be able to use during the whole script. So if you do everything in the beginning (when you open the script), it should be fine :)

And you use that function a lot ;)

Offline NecroBumpist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 130
  • Rating: +14/-5
  • Master of Lua
    • View Profile
Re: Maximum Over Drive System - Lua Assembly Toolkit
« Reply #21 on: October 06, 2011, 12:36:37 am »
Spoiler For For anyone knew to MODS, a quick summary:
The Lua language compiles to bytecode before it is ran.
Lua Assembly (LASM) is the format of this bytecode.

This thread was about my LASM assembler, named MODS (Maximum OverDrive System), but I wish to improve this.

Example LASM code:
Code: [Select]
.options 0, 0, 0, 2

getglobal 0, <"print">
loadk  1, <"hello world">
call 0, 2, 1
return 0, 1

I'm interested in reviving this project, but I need long time general assembly programmer's feedback.

I want to do two things with this project:
  • Finish 2.x by finally adding various debugging things
  • Completely redesign everything, from the parser to the linker
The 2.x line will be just about finished after I add more debugging tools such as a proper disassembler, which will output a file that can be properly parsed by MODS 2.x
However, I really dislike the way I had to implement A LOT of things, so I want to start from scratch.
To do this will require more planning, so I'm going to need to know what's actually useful in an assembler, so this is where I need help.

I've tried my hand in assembly before, briefly with x86, and I used NASM, which is where I've gotten some inspiration, but because of the limited time I used it for, I'm probably missing some things.

I incorporated NASM like macros into v2, which was a huge improvement, but because they were done so late in development, I did a pretty bad job of it, so they are more limited than I would of liked. This is one of the primary reasons I want to rewrite MODS.

Anyway, assemblers! Come one, come all! Please, offer your advice to me!
What sort of features do you use/like in your assemblers ?

Examples:
  • Macros
  • Labels
  • preprocessor type stuff
As I said, since I didn't get far into x86 assembly, I need help with ideas for MODS 3.
Developing Lua scripts for the NSpire ?
Check out the Necrotorium
Need a few routines to run faster ? Checkout the MODS Lua Assembly Toolkit.
Need to save space for your scripts ? Checkout LuaSrcDiet

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Maximum Over Drive System - Lua Assembly Toolkit
« Reply #22 on: October 06, 2011, 01:44:48 am »
As much as I would like to help, I cant, as I don't know asm of any kind.
Good luck anyway!