user336462
user336462

Reputation: 431

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.

Upvotes: 5

Views: 3055

Answers (3)

The OS may define the calling standard (it pretty well must define the standard for invoking system calls), in which case you need only find where that is documents and read it closely.

Upvotes: 2

Greg Hewgill
Greg Hewgill

Reputation: 994529

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.

Upvotes: 10

Rom
Rom

Reputation: 4199

  1. push parameter on the stack
  2. call the function
  3. clear the stack

The links you have in your question show all these steps.

Upvotes: 1

Related Questions