Article Index

Because this example is part of a rebuild, the include files don't match with the proposed nasm include file directory. Adjust as needed.

;name: simple.asm
;
;description: A simple window
;
;source: http://zetcode.com/gui/gtk2/firstprograms/
;
;build:
;   nasm -felf64 simple.asm -o simple.o
;   ld -s -melf_x86_64 simple.o -o simple --dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc `pkg-config --libs gtk+-2.0`

bits 64

%include "simple.inc"

global _start

section .bss
    window:	resq  1

section	.rodata
    signal:
    .destroy:	db  "destroy",0
    
section .data
    
section .text

_start:
    ;initialize without arguments from commandline
    call    gtk_init
    ;create a new window
    xor	    rdi,rdi			;GTK_WINDOW_TOPLEVEL=0
    call    gtk_window_new		;rax = pointer to window
    mov	    qword[window],rax
    ;show the window
    mov	    rdi,rax			;rdi = pointer to window
    call    gtk_widget_show
    ;connect the destroy window handler
    mov	    rdi,qword[window]
    mov	    rsi,signal.destroy
    mov	    rdx,gtk_main_quit
    xor     rcx, rcx                    ;pointer to the data to pass
    ;don't forget the next two instructions or the application
    ;will be "unexpectedly finished"
    xor     r9d, r9d                    ;combination of GConnectFlags 
    xor     r8d, r8d                    ;a GClosureNotify for data
    call    g_signal_connect_data
    ;main window loop
    call    gtk_main
    ;exit program
    xor	    rdi,rdi
    call    exit