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: center.asm
;description: Center the window on screen.
;   nasm -felf64 center.asm -o center.o
;   ld -s -melf_x86_64 center.o -o center --dynamic-linker /lib64/ -lc `pkg-config --libs gtk+-2.0`

bits 64

%include ""

global _start

section .bss
    window:	resq  1

section	.rodata
    .destroy:	db  "destroy",0
    title:	db  "Center",0
section .data
section .text

    ;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
    ;set the window title
    mov	    rsi,title			;set window title
    mov	    rdi,qword[window]
    call    gtk_window_set_title
    ;set the size of the window
    mov	    rdx,150			;height of window
    mov	    rsi,230			;width of window
    mov	    rdi,qword[window]
    call    gtk_window_set_default_size
    ;set the position of the window
    mov	    rsi,GTK_WIN_POS_CENTER	;center window on screen
    mov	    rdi,qword[window]
    call    gtk_window_set_position
    ;show the window
    mov	    rdi,qword[window]		;rdi = pointer to window
    call    gtk_widget_show
    ;connect the destroy signal to gtk_main_quit
    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
    ;run main window routine
    call    gtk_main
    ;exit program
    xor	    rdi,rdi
    call    exit