Xlib and assembly?

Programming, for all ages and all languages.
Post Reply
skid
Posts: 11
Joined: Wed Dec 17, 2014 12:43 pm

Xlib and assembly?

Post by skid »

Anyone got experience with Xlib/xcb for linux and assembly? basically i would like to start "hacking" http://incise.org/tinywm.html but dont know how to link / compile to the lib

re
skid
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Xlib and assembly?

Post by iansjack »

I'm not quite sure that I understand what your problem is. You call Xlib functions just like you would any other library. Or am I missing something?
skid
Posts: 11
Joined: Wed Dec 17, 2014 12:43 pm

Re: Xlib and assembly?

Post by skid »

care to give an example, i've been out of the game for quite som time and become literally stupid ;)
no92
Member
Member
Posts: 307
Joined: Wed Oct 30, 2013 1:57 pm
Libera.chat IRC: no92
Location: Germany
Contact:

Re: Xlib and assembly?

Post by no92 »

Asking for the solution is not something that makes you look good. It makes you look like a complete idiot. As someone has in his sig, computer science is all about problem solving. By asking for the solution, you're basically defeating the purpose. Even if this does not reflect this case, it shows you one thing: we only provide help that helps you to find the solution by yourself.

Take a look at the System V ABI. It tells you how to call a function. If you're not familiar with gcc or ld, there's nothing for you to do here. Go learn to use it first (e.g. by taking a look at the man pages ...). I'm sorry if it sounds very rude, but that's the truth.
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Xlib and assembly?

Post by Antti »

In general, if I were interested in using X11, I would start studying the X Window System Protocol.

Code: Select all

ChangeWindowAttributes
     1     2                               opcode
     1                                     unused
     2     3+n                             request length
     4     WINDOW                          window
     4     BITMASK                         value-mask (has n bits set to 1)
          encodings are the same as for CreateWindow
     4n     LISTofVALUE                    value-list
          encodings are the same as for CreateWindow

I am not interested using it (and I am no familiar with it) but I kind of like these kind of interfaces. There are no specific programming languages involved. Send an opcode and then parameters into some messaging system...
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Xlib and assembly?

Post by iansjack »

skid wrote:care to give an example, i've been out of the game for quite som time and become literally stupid ;)
TBH, if you are not up to reading and understanding the X Window and Xlib documentation then you are not going to have much success "hacking" a window manager. Start with something simpler and practise calling C libraries from assembler. When you are confident with that you can come back to using this particular library.
skid
Posts: 11
Joined: Wed Dec 17, 2014 12:43 pm

Re: Xlib and assembly?

Post by skid »

i get the picture and i think i understand but could someone please give me an idea howto build the structure for Display for example, guess one way would be to put extern Display * dpy in a c file and link, but i want to learn but i dont understand. i'm not asking for anyone to write me an entire program here, only minor guidance, and explain in a language i can understand or begin to understand. i used to do dos assembly years ago, i'm sorry i have blown my brains on dope...

http://www.x.org/releases/current/doc/x ... tion_Setup
what am i supposed to to with this, a snippet is all i ask.
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: Xlib and assembly?

Post by FallenAvatar »

skid wrote:i get the picture and i think i understand but could someone please give me an idea howto build the structure for Display for example, guess one way would be to put extern Display * dpy in a c file and link, but i want to learn but i dont understand. i'm not asking for anyone to write me an entire program here, only minor guidance, and explain in a language i can understand or begin to understand. i used to do dos assembly years ago, i'm sorry i have blown my brains on dope...

http://www.x.org/releases/current/doc/x ... tion_Setup
what am i supposed to to with this, a snippet is all i ask.
Everything you need to know is at http://www.cprogramming.com/

- Monk
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Xlib and assembly?

Post by iansjack »

skid wrote:i get the picture and i think i understand but could someone please give me an idea howto build the structure for Display for example, guess one way would be to put extern Display * dpy in a c file and link, but i want to learn but i dont understand. i'm not asking for anyone to write me an entire program here, only minor guidance, and explain in a language i can understand or begin to understand. i used to do dos assembly years ago, i'm sorry i have blown my brains on dope...

http://www.x.org/releases/current/doc/x ... tion_Setup
what am i supposed to to with this, a snippet is all i ask.
You are not asking how to use Xlib or how to do XWindow programming. You are asking how to use any external C function or library from assembler (in this case how to build the assembler equivalent of a C struct). This is not really the level that this forum is aimed at.

I repeat my previous advice - before being so ambitious learn and practise the basics with simpler C libraries. Once you understand them you can return to this more advanced project. There are plenty of web sites and/or books that will provide help with these basics of assembler programming.
skid
Posts: 11
Joined: Wed Dec 17, 2014 12:43 pm

Re: Xlib and assembly?

Post by skid »

am i on the right path atleast?

Code: Select all

extern XOpenDisplay
extern DefaultRootWindow

	push 0
	call XOpenDisplay
	or eax, eax
	je fail
	;add esp, 4
	mov [display], eax

	push display
	call DefaultRootWindow
	;add esp, 8
	mov [root], eax

fail: 
	; print something

display 		dd 0
root 	dd 0

User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Xlib and assembly?

Post by iansjack »

A good way to check what you need to do in assembler is to create a simple program in C and compile it. Look at the assembler output produced.

A better way is just to use C in the first place. :)
Post Reply