Page 1 of 1

Creating costume asmcode with a C-compiler

Posted: Thu Apr 25, 2002 4:41 pm
by smurphy
Is it possible to configure, for example GCC, to create costume asmcode for an operating system?

Linux dosnt look like Windows when you look upon it from a asm'ers view. You dosnt push all the parameters and then call for interrupt 0x80 in linux.. But i guess you already knew that :P

Is it possible to change the way the compiler compiles code (and i am not talking about rewriting it)? There are lots of ways a simple piece of code could be compiled (into).

just consider this:

(both k and a are integers)

k++;
a = k;

translated to asm:

mov eax, [k_variable]
inc eax
mov [k_variable], eax
mov [a_variable], eax

or

mov eax, [ebp+8]
inc eax
mov [ebp+8], eax
mov [ebp+4], eax

etc etc etc.

I would like to create costume asmcode for my operating system. I WANT to control every single piece of my code! >:(
If there is no way to do this, is there any other way to do it? If so, how?

Hum. I guess i made my point. Youll have to excuse me, it's late here in sweden now :P

Anyone?

// SMURPHY - the guy in your head

Re:Creating costume asmcode with a C-compiler

Posted: Thu Apr 25, 2002 6:03 pm
by Tim
Why? You can't change the machine code -- that is hard-coded into the processor (or the processor's microcode at least). All you could do would be to create your own syntax for the same instruction set, and modify gcc to use your syntax. However, that would be almost pointless, because nobody would ever see it. Modifying gcc is also said to be quite difficult.

All in all, changing the assembly language is either impossible (at the opcode level) or pointless (at the syntax level).

Re:Creating costume asmcode with a C-compiler

Posted: Fri Apr 26, 2002 3:30 am
by smurphy
I did not mean that i would want to change the opcodes. And yes, i know that's impossible. That was rude.
But i did want to make gcc (or any other compiler) to create alternative asmcode.

Why are you writing an operating system?
Is it to explore the system?
Is it that you would be able to say that "i did all that myself. there IS NO OTHER code than MINE in there!"?

If you dont care how the code will be like, you have already abandoned the above ideas behind writing your own operating system.

But IF you are a meaningless deskworker siting in a paper-cube, maybe that's just OK?

I am not a worker. I am doing this at my own. I WANT to do this.

// SMURPHY - the guy in your head

Re:Creating costume asmcode with a C-compiler

Posted: Fri Apr 26, 2002 8:45 am
by Dave_Hunt
Well, if you really want to do it ALL yourself, then you shouldn't be using an existing compiler. You should write your own.

The code generated by the compiler has nothing to do with the design of an operating system (with the possible exception of function calling conventions). You don't explore the system by generating code. You do that by writing memory management functions, task switching, device drivers, filesystem interfaces, etc.

The differences in how applications make calls into the operating system are not handled by the compiler. They are handled by library routines that take care of the details.

Having said all that, if you really want to control the code generated by the compiler, the only way to do that is to write your own compiler.

By the way, Tim wasn't being "rude." He simply misunderstood your question.