flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
BPS
Hello
![]() I'm currently learning assembler (FASM) for fun, so I started to rewrite some of my C programs. I have program which uses GTK, it creates status icon: main.c ===== Code: ... int main(void) { gtk_init(0, 0); // Status icon GtkStatusIcon *status_icon = gtk_status_icon_new_from_icon_name("exit"); g_signal_connect(status_icon, "button-press-event", G_CALLBACK(on_button_press), 0); // main loop gtk_main(); return 0; } and now I'm trying to translate above to assembler. Right now I got this: main.asm ======== Code: ... main: push 0 push 0 call gtk_init add esp, 8 push status_icon_stock call gtk_status_icon_new_from_icon_name add esp, 4 mov eax, [status_icon] push 0 push 0 push 0 push on_button_press push button_press_event push [status_icon] call g_signal_connect_data add esp, 24 call gtk_main status_icon dd 0 exit_dialog dd 0 vbox dd 0 exit_button dd 0 status_icon_stock db 'exit', 0 clicked_str db 'clicked', 0 application_exit_stock db 'application-exit', 0 button_press_event db 'button-press-event', 0 But when I try to run it I get error saying that status_icon is NULL. Why my C code is working and assembly is not? Am I missing something? mov eax, [status_icon] does not put valid pointer in status_code variable? Full code can be viewed here: https://github.com/4544fa8d/i3-exit thanks ![]() |
|||
![]() |
|
revolution
I think you forgot to save the handle:
Code: ;... call gtk_status_icon_new_from_icon_name mov [status_icon],eax ;<--- save the handle here add esp, 4 ;... |
|||
![]() |
|
BPS
Och, I switched places of source and destination, I don't know how could have I missed it
![]() Thanks Now I moved forward and have another error: Code: on_button_press: ... cmp eax, GTK_RESPONSE_CLOSE jne return mov eax, 11 ;sys_execve mov ebx, dbus_filename mov ecx, dbus_shutdown_args mov edx, 0 int 80h call gtk_main_quit return: push [exit_dialog] call gtk_widget_destroy add esp, 4 ; int 03h ret ; <- Segmentation fault (core dumped) int 03h main: ... push 0 push 0 push 0 push on_button_press push button_press_event push [status_icon] call g_signal_connect_data add esp, 24 call gtk_main Breakpoint show that "segmentation fault" on ret instruction in my "on_button" function. How can I return from on_button function? Full updated code is at: https://github.com/4544fa8d/i3-exit thanks ![]() |
|||
![]() |
|
revolution
So I expect you have some stack corruption in there somewhere. You didn't show all the code* so I can only guess.
* I see the github link. Not going there, sorry. |
|||
![]() |
|
revolution
At first glance there does not appear to be anything obvious wrong.
You can try a few things though. Check that the stack pointer the same upon entry and just before the ret. And/or, simplify the entire procedure to just a ret (or maybe some minimal instructions) and see if that exhibits the same problem. |
|||
![]() |
|
petelomax
hasty post deleted [after posting I saw dbus_shudown_args had already been fixed]
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.