NASM - The Netwide Assembler
NASM Forum => Example Code => Topic started by: Gunner 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 (http://www.dreamincode.net/forums/topic/287274-nasm-linux-dynamic-memory-allocationread-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.
-
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:
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.
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:
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
-
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.
-
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!
-
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. ;)
-
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!
-
Next one up:
NASM - Using GTK+ (http://www.dreamincode.net/forums/topic/288358-nasm-using-gtk/page__pid__1681243__st__0entry1681243)
-
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
-
Oh they joys of Linux :o
That would be libgtk-3-0 I believe, correct?
-
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
-
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!
-
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!
-
Yep, that works. Nice. Thanks, Gunner!
Best,
Frank
-
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**/ (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.
-
Damn swear filter!
Ok, the Cross OS App for Linux/Windows using GTK (http://www.dreamincode.net/forums/topic/292403-nasm-cross-os-app-for-linuxwindows-using-gtk/) tutorial is complete.
-
Damn swear filter!
It appears that the filter does not function at 100% efficiency! ;D
-
Expletive deleted good job, Gunner! Battle to the end!
The distributed executable dies with "floating point exception" on my system. Haven't looked into why. Been lazy lately. ("lately"?... "as usual"!). "error: system too obsolete" probably... Thanks!
Best,
Frank
-
Unsure why. As I pointed out in the tut, there is absolutely no error checking to keep it simple. I do know that error comes from somewhere in the GTK libs.
Glad to be of help :-)
-
"Cross OS App for Linux/Windows using GTK" idea really inspired me.
I have created an include file for gtk (gtk.inc) and hll.inc (mostly useful generic macros from nagoa+.inc) in the hope that Gtk programs written using this can be compiled and executed in both platforms without any change.
I have attached the zip file containing
gtkwin.asm
hll.inc
gtk.inc
I have validated these in windows, but i don't have access to linux now, It would be great if Gunner or someone can validate this in linux and update.
For windows All you need is nasm, golink and the gtk runtime dlls.
You can visit
http://www.gtk.org/download/win32.php (http://www.gtk.org/download/win32.php)
to get the runtime dlls or download from
http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip)
Extract the dlls from the zip file to windows\system32 folder so that golink can find them. It worked for me :)
(The program displays a window with two controls and a pop up.)
The example program(gtkwin.asm) is translated from the following C Version.
#include <windows.h>
#include <gtk/gtk.h>
static GtkWidget *entry;
GtkWidget *window;
static gboolean kill_window(GtkWidget *widget, GdkEvent *event, gpointer data)
{
gtk_main_quit();
return FALSE;
}
static void button_press(GtkWidget *widget, gpointer data)
{
const char *text = gtk_entry_get_text(GTK_ENTRY(entry));
GtkWidget *msgbox;
msgbox = gtk_message_dialog_new(window,GTK_DIALOG_DESTROY_WITH_PARENT ,GTK_MESSAGE_INFO ,GTK_BUTTONS_OK ,text);
gtk_window_set_title(GTK_WINDOW(msgbox), "Info");
gtk_dialog_run(GTK_DIALOG(msgbox));
gtk_widget_destroy(msgbox);
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
GtkWidget *button;
GtkWidget *hbox;
gtk_init_abi_check(NULL, NULL,2,sizeof(GtkWindow),sizeof(GtkBox));
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
button = gtk_button_new_with_label("Echo");
entry = gtk_entry_new();
hbox = gtk_hbox_new(FALSE, 2);
gtk_window_set_title(GTK_WINDOW(window), "GTK application");
g_signal_connect_data (window, "delete_event", G_CALLBACK(kill_window), NULL, NULL, (GConnectFlags) 0);
g_signal_connect_data (button, "clicked", G_CALLBACK(button_press), NULL, NULL, (GConnectFlags) 0);
gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 2);
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 2);
gtk_container_add(GTK_CONTAINER(window), hbox);
gtk_widget_show_all(window);
gtk_main();
gtk_exit(0);
return 0;
}
I have not tried linking gtk programs written in nasm in linux before. i could use someone's help now.
Thanks,
Mathi.
-
Ok, finally gotten around to writing the SQLite tutorial. There will be a few tutorials on this as I have time. This part shows how to get data from a table 2 ways.
NASM - Using SQLite (Querying data from a table) (http://www.dreamincode.net/forums/topic/319986-nasm-using-sqlite-querying-data-from-a-table/page__pid__1844695__st__0entry1844695)
-
Hi Gunner,
your tutorials are very good. Thzank you for that.
Gerhard