-1

I was wondering how OS API works, since I decided to write a compiler. You probably invoke a API if you're doing something in C/C++. They seem very fine in C/C++, but I am very confused as to how they are compiled to in assembly. Do they issue an interrupt, write to a memory address, write to a register and then issue an interrupt (thats how BIOS API works, I'm not sure if OS API works like that) or something else?

  • Your questions sadly imply a great lack of basic knowledge to low level programming. I suggest that you get yourself a good book or two about this topic and learn about these topics before even considering writing your own compiler. – Jan Henke Aug 26 '16 at 10:59
  • A relevant term here is "calling convention" (for how function args are passed, and return values are returned, and which registers are clobbered and which aren't). More generally, ABI (like API but Binary) describes how things interact with each other in assembly. The [x86 tag wiki](http://stackoverflow.com/tags/x86/info) has some good links about what an ABI is, and links to the official specs for the common ones used on x86 / x86-64 (including stuff like the Linux system-call ABI, which unlike Windows is stable and can be used directly, without the usual glibc wrappers) – Peter Cordes Aug 26 '16 at 11:58
  • That seemed like the most relevant duplicate, even though I know you're actually interested in Windows. See also http://stackoverflow.com/questions/8335582/why-does-ia-32-have-a-non-intuitive-caller-and-callee-register-saving-convention for some discussion of why calling conventions are designed the way they are. See also [x86 Linux 32-bit assembly Hello World, with pure system calls (no libc) on SO docs](http://stackoverflow.com/documentation/x86/1164/introduction-to-x86/19078/x86-linux-hello-world-example). – Peter Cordes Aug 26 '16 at 12:22
  • Wrong, I'm not interested in Windows. I'm interested in having an API for an operating system I am creating – Shaheer Rizvi Aug 26 '16 at 13:14

1 Answers1

2

sorry for answering my own question, but I found what I was looking for

Apparently OS API (at least in windows) is just a standard C call, which means that if I'm writing my compiler I need to implement my own API system.

Source: https://social.msdn.microsoft.com/Forums/en-US/61b11104-98c1-43aa-be19-91378561bab4/calling-win32-api-from-assembly-language?forum=netfxtoolsdev