Author Topic: Linux/NASM Tutorials  (Read 32900 times)

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Linux/NASM Tutorials
« on: July 28, 2012, 10:20:35 PM »
As I write tutorials, I will post links to them here (If you all don't mind)

Here is the third one: NASM - Linux Dynamic Memory Allocation/Read file

The two before this, I need to fix a few typos and then I will post the links, but they are around the above one if you want them as is.

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: Linux/NASM Tutorials
« Reply #1 on: July 29, 2012, 02:09:28 AM »
Gunner,

Nice job on the new tutorial. But I have to ask. Did you modify the above example before publishing? I'm bad about doing that as well (Frank usually calls me on it though ;D) Line 57 in the above example uses "sys_stat" but it's not defined, it should probably be changed to "sys_newstat". It's actually correct in the file_read.tar.gz, just not the post.

Tip:
Since you're using the sizeof(x) macro, when creating string length equates like:
Code: [Select]
orgbreak    db      "Original break = "
orglen      equ     $-orgbreak

newbreak    db      "New break = "
newlen      equ     $-newbreak

filesize    db      "Filesize = "
filelen     equ     $-filesize
diff        db      "Difference = "
difflen     equ     $-diff

Try to name them with a _size suffix for consistency.
Code: [Select]
orgbreak           db      "Original break = "
orgbreak_size      equ     $-orgbreak

newbreak           db      "New break = "
newbreak_size      equ     $-newbreak

filesize           db      "Filesize = "
filesize_size      equ     $-filesize
diff               db      "Difference = "
diff_size          equ     $-diff

This way, later on when you use sys_write, you can do so like:
Code: [Select]
mov     ebx, stdout
mov     ecx, diff
mov     edx, sizeof(diff)
mov     eax, sys_write
int     80h

More of a coding style thing, but it provides a nice bit of consistency. :)

Regards,
Bryant Keller

About Bryant Keller
bkeller@about.me

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Linux/NASM Tutorials
« Reply #2 on: July 29, 2012, 02:34:06 AM »
Oh crap, did I do that.  Yes, quite a few modifications. sys_stat was the original code that I could not get to work without hacks till I found something on sys_newstat and the "new" stat structure.  As long as the gz has the correct code, that is fine for now. 

Thanks, I will fix that fixed!

and thanks for the sizeof tip.

« Last Edit: July 29, 2012, 02:37:17 AM by Gunner »

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Linux/NASM Tutorials
« Reply #3 on: July 29, 2012, 04:26:47 PM »
I am a big fan of SQLite, have used it for a few projects on Windows using MASM.  For Assembly on Linux, documentation and samples seem to be non-existent!  Any "hints" I have found are from some FASM stuff.  I think this will be my next tutorial.  I am glad I have 2 weeks off!!  :-)  This looks like it will be a long and rough journey!

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Linux/NASM Tutorials
« Reply #4 on: July 29, 2012, 11:35:20 PM »
Man, I was I had a few weeks off right now!  :'(

Anyways, looking forward to seeing your writings.  I'm sure lots of folks will benefit from your experience.  ;)

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Linux/NASM Tutorials
« Reply #5 on: July 29, 2012, 11:40:45 PM »
Yeah, it is nice.  Shop closes for 2 weeks at this time and for xmas, so a month paid every year is sweet!

So far it isn't bad at all, got the inc file with all the SQLite defines done.  Figured out how to link to libsqlite3.so.0.  If I get too bored, I might translate the structures (I think this is for the future).  I am using the MASM code from one of my projects as reference, so we will see.

Keep you posted!

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Linux/NASM Tutorials
« Reply #6 on: August 09, 2012, 02:34:35 AM »
Next one up:
NASM - Using GTK+

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Linux/NASM Tutorials
« Reply #7 on: August 09, 2012, 07:20:22 AM »
Thanks, Gunner!

"gtk-firstwin: error while loading shared libraries: ..."

This is no great surprise to me, but perhaps you might want to mention the requirement.

Best,
Frank


Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Linux/NASM Tutorials
« Reply #8 on: August 09, 2012, 05:22:23 PM »
Oh they joys of Linux  :o

That would be libgtk-3-0 I believe, correct?
« Last Edit: August 09, 2012, 06:12:15 PM by Gunner »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Linux/NASM Tutorials
« Reply #9 on: August 09, 2012, 10:29:04 PM »
Correct. I know what to do about it... I think. Upgrade hardware and software would be the best way! I'm not quite ready to do that yet... soon (I keep saying). Whether I can get libgtk-3.0 to install on my current system is a question. I've got libgtk-1.2. Installed it to run some examples from Numit_or, as I recall. I think that was the one that required five (5) supporting libraries installed first... in the proper order! If I've gotta upgrade each of them... I'm probably not going to bother. If you do all this, you can get pretty "advanced" stuff to run on an "obsolete" system. That's the "good" part of Linux! Doesn't cost any money, but it does require a little more "involvement" than the alternatives. Might be possible to modify your code so it works with an older lib, too. I'll look into it and see how it goes.

I can get as far as a window with just sys_calls. Maybe manage a button or two. Not a very practical thing to do. Hmmm, Jeff Owens has a library for that. I should look into that!

Best,
Frank


Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Linux/NASM Tutorials
« Reply #10 on: August 09, 2012, 10:45:28 PM »
Well, just came across glade.  Pretty cool to create a GUI.  GTK can use these xml files to load and create the frontend.  I like it so far!

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Linux/NASM Tutorials
« Reply #11 on: August 10, 2012, 05:52:03 PM »
You can always change the library to link to:
--libs gtk+-3.0 is the newer version

--libs gtk+-2.0 using this one in my port for features...

--libs gtk+-1.0 to use the tutorial code on your machine.  Just tried linking the tutorial to this, and it works fine.

The more I learn and use GTK (and Glade) the more I am blown away at all of its features!

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Linux/NASM Tutorials
« Reply #12 on: August 10, 2012, 06:07:06 PM »
Yep, that works. Nice. Thanks, Gunner!

Best,
Frank


Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Linux/NASM Tutorials
« Reply #13 on: September 17, 2012, 12:38:19 AM »
I have spent most of the day trying to create a cross OS app for Linux/Windows using NASM and GTK+.  I gave up at one point, but finally succeeded!  So, this will be the next tutorial for me.

My thoughts.
http://www.dreamincode.net/forums/blog/2070/entry-4198-nasm-and-gtk-on-windows-kicked-my-a**/

Edit by Keith: Changed the URL to include HTML entities in order to compensate for the forum "swear" filter.
« Last Edit: September 17, 2012, 10:42:21 AM by Keith Kanios »

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Linux/NASM Tutorials
« Reply #14 on: September 19, 2012, 01:25:01 AM »
Damn swear filter!

Ok, the Cross OS App for Linux/Windows using GTK tutorial is complete.