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.
;
;source: http://zetcode.com/gui/gtk2/firstprograms/
;
;build:
;   nasm -felf64 center.asm -o center.o
;   ld -s -melf_x86_64 center.o -o center --dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc `pkg-config --libs gtk+-2.0`

bits 64

%include "center.inc"

global _start

section .bss
    window:	resq  1

section	.rodata
    signal:
    .destroy:	db  "destroy",0
    title:	db  "Center",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
    ;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