Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
22 May, 2013, 15:36:47 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2   Go Down
  Print  
Author Topic: Maximum Over Drive System - Lua Assembly Toolkit -  (Read 2251 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
NecroBumpist
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 04 November, 2012, 07:02:18
Date Registered: 18 August, 2011, 05:44:50
Location: In my IDE, programming shit
Posts: 129


Topic starter
Total Post Ratings: +9

View Profile
« on: 20 August, 2011, 01:58:46 »
+4

Welp, I am in need of more posts before I can join the IRC apparently, so I will introduce you all to a project I'm working on Smiley

Since Lua is currently the fastest programming language for up-to-date NSpire calculators, I thought I would share this relevant project.
This really is for those who want to get the absolute most out of Lua. It's very impractical to write an entire program from Lua assembly, since the compiler does a decent job for most non-time-critical functions.

Lua is actually a semi-compiled language (at least that's what I'm going to call it).
It is compiled to bytecode, and than interpreted dynamically on a virtual machine.

You can execute Lua bytecode directly in Lua with the loadstring() function.


1
2
loadstring("\27\76\117\97\81\0\1\4\4\4\8\0\56\0\0\0\64\67\58\47\85\115\101\114\115\47\74\97\115\111\110\47\68\111\99\117\109\101\110\116\115\47\80\114\111\103\114\97\109\109\105\110\103\47\76\117\97\47\77\79\68\83\47\116\101\115\116\46\108\117\97\0\13\0\0\0\13\0\0\0\0\0\0\2\1\0\0\0\30\0\128\0\0\0\0\0\0\0\0\0\1\0\0\0\13\0\0\0\0\0\0\0\0\0\0\0")();

Now I'd go over the bytecode format, but you can learn all of that here
This document also includes all of the information on all of the instructions to the Lua VM.

Now, onto the project.
(In retrospect, the name I chose was rather silly, but meh, it applies)

Basically, it includes the following:
  • An assembler for a custom syntax of my own design (feature ridden)
  • Something I would call a Linker, that takes a table of all the relevant information, and compiles it into Lua bytecode
  • Soon to be a disassembler, which will turn a normal Lua function into Lua assembly.

You can find the repository here: https://github.com/NecroBumpist/MODS

So, time for "Hello World!" in Lua assembly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
local mods = require("MODS.Current.main");
local bytecode = mods.Assemble(
[[
; Hello_World.lasm
.options 0, 0, 0, 2        ; a directive, which sets some properties, the '2' meaning MaxStackSize

getglobal    0,    <'print'>        ; <> denotes a constant, i've yet to bother with a directive for doing constants
loadk        1,    <'Hello World!'> ; The LuaVM is register based, we put the function in one register, then arguments above it
call         0,    2,    1          ; now we call register 0, with (2-1) parameters, accepting (1-1) values back
return       0,    0                ; and now we return
]]);

loadstring(bytecode)() -- turns the bytecode into a function, then we call that function

>Hello World!


So,  I'd like to hear what some of you Lua users who are looking for speed improvements think Smiley
I plan on updating the repository soon to include:
  • Write some proper documentation
  • Updates to the assembler to include NASM like Macros (debugging right now)

In ten or twenty minutes the repository should be much cleaner Wink

Comments, questions, or concerns ? Or Lua Assembly general thread.
Logged

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
XVicarious
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 15 April, 2013, 12:25:41
Date Registered: 04 January, 2011, 04:04:27
Location: 127.0.0.1
Posts: 456


Total Post Ratings: +17

View Profile WWW
« Reply #1 on: 20 August, 2011, 03:44:01 »
-1

Wow. That looks pretty cool, I know no Lua at all though but still Tongue
Logged







Spoiler for Countries:


DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Online Online

Gender: Male
Last Login: Today at 15:15:35
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50216


Total Post Ratings: +2616

View Profile WWW
« Reply #2 on: 20 August, 2011, 04:48:41 »
0

Hmm Interesting. I unfortunately no longer am into programming but I'M glad to see more programming tools coming out. For which platforms will this be?
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Juju
Evil Fluttershy (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Coder Of Tomorrow
LV12 Extreme Poster (Next: 5000)
*
Offline Offline

Gender: Male
Last Login: Today at 09:00:39
Date Registered: 17 March, 2010, 07:46:57
Location: Québec, North Equestria
Posts: 4543


Total Post Ratings: +394

View Profile WWW
« Reply #3 on: 20 August, 2011, 05:26:00 »
0

Looks real nice. So that means another programming language for the NSpire? (And maybe anything that runs Lua?) Cool.
Logged

LuaIDE
Reuben Quest HD: The PC Remake
Zarmina Project: Play Read
Nspire I/O: Info Download


THEGAME
Spoiler for Other stuff:
Also Yuki "ジュジュ" Kagayaki
Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads
Find what P+4zJ means and you get free candy! cc4daa9c4645bd123ed22e385ed701fd
#omnimaga on OmniNet, EFNet and Pesterchum
Omnimaga Owner and Former Administrator
Fan of My Little Jim Bauwens: Losing the Game is Magic
Proud member of POLN - Ponys Oppositing Lol Names
Member of OBEL - Omnimaga Board of the EFnrgelnicshh Language - Office Omnimagois de la Langue FArnagnlçaaiiss
あなたはこのゲームを失った
Spoiler for Old spoileryception stuff:

Spoiler for Coming soon...:
Indefinitely halted [|.........] 10%
OmnomIRC Mobile [||||......] 40% (argh threads >_<)
Spoiler for Current/Past TI-related projects:
The Axe Parser Wiki / Founder and maintainer
Keytar Hero [|||||_____] 50% Engine done, wackiness left to do (Halted)
OmniOS
VVVVVV [||||______] 40% (Made most of the engine, extremely glitchy) (Gave it to Leafy)
░█▀█░█░█░█▀▀░█▀█░█▀█░█▀█░▀█▀░█▀▄
░█▀█░▄▀▄░█▀▀░█▀█░█░█░█░█░░█░░█░█
v0.1.0
░▀░▀░▀░▀░▀▀▀░▀░▀░▀░▀░▀▀▀░▀▀▀░▀▀░[|||||||||¦] 95ish% (Completed)
tilibs-wii? [._________] 0% (Nope.)
Spoiler for Spoilers:
<!---->
wxWabbitemu Developer
Spoiler for Other Userbars:






<!--Everything done, got 90% Cheesy sudo apt-get install z80asm z80dasm-->
Spoiler for Quote:
We are in 2034. The situation on Earth is catastrophic. The ozone layer has been completely destroyed by the carbonic gas of automobiles, the chemical industries, and the poosh-poosh in little cans. In the end, the earth cooks under the rays of the sun. We must find a planet on which can live 6 billion idiots. The planetary federation turns to the strongest country in the world: Canada. It is Canadian knowledge that has allowed, on October 28, 2034, the launch of the spaceship Romano Fafard, which leaves earth to search the confines of the Universe. Where the hand of man has never set foot.
I hate TI right now
Quote from: jimbauwens
You make me lose the game
Everytime I read your name
Spoiler for The real answer to life, the universe and everything:
Spoiler for Old HTML stuff:
<div style="margin:20px; margin-top:5px"><div class="smallfont" style="margin-bottom:2px">Spoiler for This is another spoiler: <input type="button" value="Show" style="width:60px;font-size:10px;margin:0px;padding:0px;" onclick="window.location.replace('http://goo.gl/QMET');"></div><div class="alt2" style="margin: 0px; padding: 6px; border: 1px inset;"><div style="display: none; ">HAHAHA SUCCESSFUL RICKROLL IS SUCCESSFUL</div></div></div><!-- old avatars:
http://fc00.deviantart.net/fs71/f/2011/120/d/f/nepeta_nyan_cat_by_supuru-d3f8tcx.gif
http://th01.deviantart.net/fs70/PRE/i/2011/099/5/b/rainbow_dash_derping_by_moongazeponies-d3dmg7l.png--><!---->
I may or may not be inactive during work hours (9AM to 5PM EST, Monday to Friday), so for any inquiries please leave a message after the beep and I'll answer you when I have time. Beep. Nevermind, I'm on vacation now. Cheesy
pianoman
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 20 October, 2011, 04:23:28
Date Registered: 21 May, 2011, 19:13:57
Location: You can know that my current velocity is about 0 m/s.
Posts: 427


Total Post Ratings: +24

View Profile
« Reply #4 on: 20 August, 2011, 05:31:09 »
0

Wow, looks pretty nice Smiley
Can't wait for it to be finished Cheesy
Logged

NecroBumpist
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 04 November, 2012, 07:02:18
Date Registered: 18 August, 2011, 05:44:50
Location: In my IDE, programming shit
Posts: 129


Topic starter
Total Post Ratings: +9

View Profile
« Reply #5 on: 20 August, 2011, 06:38:32 »
0

Hmm Interesting. I unfortunately no longer am into programming but I'M glad to see more programming tools coming out. For which platforms will this be?
I've yet to run the assembler/linker on calc (the code is horendous (no planning), and it would be really slow for large files.

But I'm mainly posting it because you can utilize whatever code you assemble on any platform that runs Lua.
So basically the NSpire series Smiley

Looks real nice. So that means another programming language for the NSpire? (And maybe anything that runs Lua?) Cool.
I'm not sure I would call it an entire new language, since the code it produces is ran normally in Lua. It's just a more minimalistic version of Lua.
So if you do your planning, you could definetly organize your code in way that would be better than the standard Lua compiler.
How much better, I do not know.

It's similar to the coding in C vs. ASM for x86. The best C compilers are better than average ASM coders.
But then again, the Lua compiler really does no optimzations at all. Writing important functions in Lua ASM might be of benefit, but writing simple or non-time-critical functions would likely be a waste of time.

I plan to do an example with a SHA256 algorithm tomorrow, one in normal Lua, another specifically in Lua ASM.
(I'm going to use an external library, so it won't run on calc, but it will show how Lua ASM can be helpful)
« Last Edit: 20 August, 2011, 06:40:41 by NecroBumpist » Logged

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
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Online Online

Gender: Male
Last Login: Today at 15:15:35
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50216


Total Post Ratings: +2616

View Profile WWW
« Reply #6 on: 20 August, 2011, 08:08:39 »
0

Ah ok thanks for the info.
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 08:05:41
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #7 on: 20 August, 2011, 11:20:24 »
0

Very interesting!
I have yet to try if it actually works on the nspire, but if it does,that would be wonderfull Smiley
I've got lots of routines that could use a speed boost Smiley

Thanks for your work Smiley
Logged

pianoman
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 20 October, 2011, 04:23:28
Date Registered: 21 May, 2011, 19:13:57
Location: You can know that my current velocity is about 0 m/s.
Posts: 427


Total Post Ratings: +24

View Profile
« Reply #8 on: 21 August, 2011, 01:55:21 »
0

How exactly would we include this stuff in the actual script, though?
Logged

NecroBumpist
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 04 November, 2012, 07:02:18
Date Registered: 18 August, 2011, 05:44:50
Location: In my IDE, programming shit
Posts: 129


Topic starter
Total Post Ratings: +9

View Profile
« Reply #9 on: 21 August, 2011, 02:16:21 »
0

Update to v2.2
Now includes NASM like macros:


1
2
3
4
5
6
7
8
9
10
11
12
13
.options 0, 0, 0, 200 ; yay for large stacks!

.macro print(s, msg){
    getglobal   s,  <'print'>
    loadk       s + 1,  msg
    call        s,  2,  1
}

print   0, <"Omnimaga :)">      ; this line will be replaced with everything in the print macro (this is good for inlining functions and stuff)
return  0,  0

>Omnimaga :)

It took forever to get this shit working, mainly because of my terrible code layout Tongue

Anyway, v2.3 will include cool stuff like automatically tracking the top of the stack so you don't have to use .options in every prototype, and LOTS of linker stage checks. This will prevent (well, help you figure out) the common "invalid bytecode" warnings loadstring() returns if you try to load bad code.

More can be read in the README in the repository.


How exactly would we include this stuff in the actual script, though?

You'd use the loadstring() function to convert the code Assemble() returns into a proper Lua function, which you can easily call and pass arguments to from your normal scripts.


1
2
3
4
5
6
7
local mods = require("current");
local code = mods.Assemble([[
; put cool Lua ASM code here
]]);

print(code:gsub(".", function(a) return "\\" .. a:byte() end)) -- turn the code into an escape sequence

1
2
3
4
local code = "" -- copy and paste the output of the previous script here
local func = loadstring(code);
func()
Logged

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
adriweb
Editor
LV9 Veteran (Next: 1337)
*
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 00:38:33
Date Registered: 13 April, 2011, 18:42:59
Location: South of France
Posts: 1196


Total Post Ratings: +185

View Profile WWW
« Reply #10 on: 21 August, 2011, 13:29:57 »
0

Really nice indeed.

Looking forward to be able to test that project in more complex situations, once I understand how to program in this asm-looking language Tongue
Logged


TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation
NecroBumpist
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 04 November, 2012, 07:02:18
Date Registered: 18 August, 2011, 05:44:50
Location: In my IDE, programming shit
Posts: 129


Topic starter
Total Post Ratings: +9

View Profile
« Reply #11 on: 21 August, 2011, 16:41:59 »
0

Really nice indeed.

Looking forward to be able to test that project in more complex situations, once I understand how to program in this asm-looking language Tongue

Thanks Smiley
I definetely do more basic documentation on the features of the assembler.

After that, I've included a copy of ANoFrillsIntroToLua51VMInstructions.pdf in the \docs\ folder(the de facto document for learning Lua bytecode, and ultimately Lua assembly)
So that should  be a great reference to all those who want to learn the specifics of a particular instruction.

I'll get to work on explaining how to use everything now  Grin
Logged

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
Levak
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: Today at 13:33:48
Date Registered: 04 April, 2010, 23:42:49
Location: France
Posts: 842


Total Post Ratings: +148

View Profile WWW
« Reply #12 on: 21 August, 2011, 17:49:02 »
0

Err,
Either I'm stupid (and this is not impossible), or I don't understand how you can excecute this function in the Lua TI-Nspire API :


1
require("MODS.Current.main");
Logged

Human always wants to survive and that's why he will fall one day.
My website - TI-Planet - iNspired-Lua
NecroBumpist
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 04 November, 2012, 07:02:18
Date Registered: 18 August, 2011, 05:44:50
Location: In my IDE, programming shit
Posts: 129


Topic starter
Total Post Ratings: +9

View Profile
« Reply #13 on: 21 August, 2011, 17:56:46 »
0

Yes, that wouldn't run, TI removed file interactions. The examples are really meant to be ran on a desktop.

I would not advocate using this on your calculator (as I've said before, it's slow),
but I'll steal ocLua's concept so you can, just for fun Smiley

Edit: in the \bin\ directory there is now a "ocLASM.tns" file. It works exactly like ocLua (many many thanks to ExtendeD Smiley)
Though I still don't recommend actually typing LASM on an NSpire, as it is really tedious.
« Last Edit: 21 August, 2011, 19:29:39 by NecroBumpist » Logged

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
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: Today at 10:41:34
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Total Post Ratings: +151

View Profile
« Reply #14 on: 22 August, 2011, 16:36:51 »
0

Interesting project Smiley
I'd love to see how TI-Nspire programs will benefit from it.
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.297 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.