Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use C libraries in assembler?

I want to know how to write a text editor in assembler. But modern operating systems require C libraries, particularly for their windowing systems. I found this page, which has helped me a lot.

But I wonder if there are details I should know. I know enough assembler to write programs that will use windows in Linux using GTK+, but I want to be able to understand what I have to send to a function for it to be a valid input, so that it will be easier to make use of all C libraries. For interfacing between C and x86 assembler, I know what can be learned from this page, and little else.

like image 284
user336462 Avatar asked Dec 12 '22 09:12

user336462


1 Answers

One of the most instructive ways to learn how to call C from assembler is to:

  1. Write a C program that calls the C function of interest
  2. Compile it, and look at the assembly listing (gcc -S)

This approach makes it easy to experiment by starting with something that is already known to work. You can change the C source and see how the generated code changes, and you can start with the generated code and modify it yourself.

like image 90
Greg Hewgill Avatar answered Dec 14 '22 22:12

Greg Hewgill