c, producing code
c, producing code
- How do i setup target cpu in gcc? I want it to use only instructions avaiable on given cpu, for example the oldest, 8086. Or ia64. Or any other popular cpu. The reason is i want my code to run on cpu i want it to run. How do i do that? If its impossible for some reasons dont read further jsut tell me.
- How do i compile code without linking? I want to compile code, and load it to bochs and i want it to run as easly as i would do it in asm. How do i setup padding, so my code will be matched to exact size of a sector? I need it to run code in emulator, wich wont if my code size isnt aligned properly.
- Is using c really good idea? Currently i am ready to switch to c from asm, because i cant handle complicated code in other way than using tons of local variables. I belive that c can do it better, and writing in asm is unneeded, i hope. I am ready to give a c a serious try, but if i find something that i can do in asm but cant do in c because developers of c decided that its 'too old', and removed it to make people forget about it, im done with c. So if you know of such things in c, tell me now, so i wont waste my time any longer.
- I want to use c to manage my code. For example, i create a structure, and i dont want to address it via [bx + 10]. OS specyfic things like gdt i can manage by inline asm.
I just dont want to be in a situation that i need to manage many variables and i lack registers to do so. I belive c can do it for me. Is that good reason to switch to c? I dont have to even think how c store variables. I do not care as long as it will work, i dont care if var will be written to memory, or it will stay in register at all times. I cant do this optimalization on my own, either im too stupid, or i care too much about symmetry of my code. Anyway, its a massive waste of time. I dont want to write anything in asm. I want a nice way of using C.
- From what i know, c under linux/windows will link code to other stuff. Stuff like msvcrt wich i HATE beyond words. Is it possible NOT to link, just translate a function into asm instructions?
- The last think, should i really switch to c? Im having doubts, ive tried it few times in the past, and i lost interest after things i dont understand and consider useless.
Is GCC the best c compiler? Im interested in producing standard code, so after someone dissasemble it will be unable to tell what compiler was used. GCC under linux (i belive) is ok, its widespraed, and i somehow dont see anyone sued for using it without license. So dont recommend me anything made by microsoft or apple. I jsut wont even consider using it.
- How do i compile code without linking? I want to compile code, and load it to bochs and i want it to run as easly as i would do it in asm. How do i setup padding, so my code will be matched to exact size of a sector? I need it to run code in emulator, wich wont if my code size isnt aligned properly.
- Is using c really good idea? Currently i am ready to switch to c from asm, because i cant handle complicated code in other way than using tons of local variables. I belive that c can do it better, and writing in asm is unneeded, i hope. I am ready to give a c a serious try, but if i find something that i can do in asm but cant do in c because developers of c decided that its 'too old', and removed it to make people forget about it, im done with c. So if you know of such things in c, tell me now, so i wont waste my time any longer.
- I want to use c to manage my code. For example, i create a structure, and i dont want to address it via [bx + 10]. OS specyfic things like gdt i can manage by inline asm.
I just dont want to be in a situation that i need to manage many variables and i lack registers to do so. I belive c can do it for me. Is that good reason to switch to c? I dont have to even think how c store variables. I do not care as long as it will work, i dont care if var will be written to memory, or it will stay in register at all times. I cant do this optimalization on my own, either im too stupid, or i care too much about symmetry of my code. Anyway, its a massive waste of time. I dont want to write anything in asm. I want a nice way of using C.
- From what i know, c under linux/windows will link code to other stuff. Stuff like msvcrt wich i HATE beyond words. Is it possible NOT to link, just translate a function into asm instructions?
- The last think, should i really switch to c? Im having doubts, ive tried it few times in the past, and i lost interest after things i dont understand and consider useless.
Is GCC the best c compiler? Im interested in producing standard code, so after someone dissasemble it will be unable to tell what compiler was used. GCC under linux (i belive) is ok, its widespraed, and i somehow dont see anyone sued for using it without license. So dont recommend me anything made by microsoft or apple. I jsut wont even consider using it.
Re: c, producing code
- Look it up in the GCC manual.
- Look it up in the GCC manual.
- Of course you can do things in ASM that you cannot do in C (like, accessing registers, using specific opcodes etc.); if that makes you storm away in frustration, too bad.
- What?
- You get some runtime code linked in that is necessary for userspace executable startup (unless you tell the linker not to, in which case you won't get a startable userspace binary). Beyond that, you get only that stuff linked in that you actually use in your code. (Talking Unix here, not quite sure what the state of affairs is with Windows.)
- Hell no, you shouldn't switch to C. Actually, if I were to judge you only by this one post, I'd say you should drop programming alltogether.
And on the subject of whether GCC is "the best" compiler... well, is a Volkswagen the best car? The Intel compiler produces better optimized code. The Microsoft compiler is better supported for producing Windows executables. (Yes, it is. Try compiling e.g. ICU for Windows using GCC.) The Comeau compiler has a reputation for having the best frontend. It all depends what you are looking for - but since you are so caught up in what you want and what you don't want, you aren't really looking for a fair comparison. That bodes ill for your future as a programmer.
PS: Sorry, but your approach is as wrong as it could get. When you're a newbie in a field, you enter quietly, watch, ask a couple of polite questions, listen, and learn. The way you barged in with this post just shows that you expect this and expect that, and why didn't they do it the way you think would've been best? Sorry, but that's not the way things like this work.
- Look it up in the GCC manual.
- Of course you can do things in ASM that you cannot do in C (like, accessing registers, using specific opcodes etc.); if that makes you storm away in frustration, too bad.
- What?
- You get some runtime code linked in that is necessary for userspace executable startup (unless you tell the linker not to, in which case you won't get a startable userspace binary). Beyond that, you get only that stuff linked in that you actually use in your code. (Talking Unix here, not quite sure what the state of affairs is with Windows.)
- Hell no, you shouldn't switch to C. Actually, if I were to judge you only by this one post, I'd say you should drop programming alltogether.
And on the subject of whether GCC is "the best" compiler... well, is a Volkswagen the best car? The Intel compiler produces better optimized code. The Microsoft compiler is better supported for producing Windows executables. (Yes, it is. Try compiling e.g. ICU for Windows using GCC.) The Comeau compiler has a reputation for having the best frontend. It all depends what you are looking for - but since you are so caught up in what you want and what you don't want, you aren't really looking for a fair comparison. That bodes ill for your future as a programmer.
PS: Sorry, but your approach is as wrong as it could get. When you're a newbie in a field, you enter quietly, watch, ask a couple of polite questions, listen, and learn. The way you barged in with this post just shows that you expect this and expect that, and why didn't they do it the way you think would've been best? Sorry, but that's not the way things like this work.
Every good solution is obvious once you've found it.
Re: c, producing code
Im trying to set 8086 cpu, i want code for it.
If gcc cant do that, its game over for it, i will always look on c code as inferior one, and treat people using it accordingly.
From what i searched, it cant even make 16 bit code (no prefixes).
I delayed going deeper into c in favour of more important things, as its just a tool wich i will better use if i understand low level stuff.
Untill now, it was easier for me to write code in asm, because tasks i was performing werent complicated enough. Of course i can continue writing everything in asm, but i do not do ANY tricks to optimaze the code. If i did, it would be even more obscure than it is now. And i guess its slow, as i use way too much memory. On x86 wich is my main cpu it isnt as big problem as it is on other machines, with over hundred GPRs. Even if i learned every single cpu architecture there is, i would still try to make my code look simmilar on all of them. Meaning i would use only 1 accumulator and 1 address register. On ia64 with 128 gprs that would be inefficient and stupid.
You might think i didnt read the gcc manual, didnt done any research, but i did. It might not be as solid as it should be, but asking you finrst nistead of google would be inefficient. I am currently also trying to find answers, found 1 (-nostdlib remove bload), but i still dont know how do 'compile without linking' or '-march=8086'.
If gcc cant do that, its game over for it, i will always look on c code as inferior one, and treat people using it accordingly.
From what i searched, it cant even make 16 bit code (no prefixes).
I delayed going deeper into c in favour of more important things, as its just a tool wich i will better use if i understand low level stuff.
Untill now, it was easier for me to write code in asm, because tasks i was performing werent complicated enough. Of course i can continue writing everything in asm, but i do not do ANY tricks to optimaze the code. If i did, it would be even more obscure than it is now. And i guess its slow, as i use way too much memory. On x86 wich is my main cpu it isnt as big problem as it is on other machines, with over hundred GPRs. Even if i learned every single cpu architecture there is, i would still try to make my code look simmilar on all of them. Meaning i would use only 1 accumulator and 1 address register. On ia64 with 128 gprs that would be inefficient and stupid.
You might think i didnt read the gcc manual, didnt done any research, but i did. It might not be as solid as it should be, but asking you finrst nistead of google would be inefficient. I am currently also trying to find answers, found 1 (-nostdlib remove bload), but i still dont know how do 'compile without linking' or '-march=8086'.
Re: c, producing code
@Solar:
I wanted to write a similar response, but I knew I couldn't do it as well.
@OP:
Solars response may seem harsh, but it is in fact the opposite. It puts you in your place, teaching you an important lesson while still containing valuable information.
So, if you listen to what people have to say, read the wiki, search before asking, do a lot of trial an error and so on and so forth, I'm sure you'll pull through, but you really need to want it.
Best regards.
I wanted to write a similar response, but I knew I couldn't do it as well.
@OP:
Solars response may seem harsh, but it is in fact the opposite. It puts you in your place, teaching you an important lesson while still containing valuable information.
So, if you listen to what people have to say, read the wiki, search before asking, do a lot of trial an error and so on and so forth, I'm sure you'll pull through, but you really need to want it.
Best regards.
This was supposed to be a cool signature...
Re: c, producing code
And that from someone who cannot even capitalize his sentences properly.a5498828 wrote:i will always look on c code as inferior one, and treat people using it accordingly.
And why should it?From what i searched, it cant even make 16 bit code (no prefixes).
How leet of you.Even if i learned every single cpu architecture there is, i would still try to make my code look simmilar on all of them.
It's stupid even on x86.Meaning i would use only 1 accumulator and 1 address register. On ia64 with 128 gprs that would be inefficient and stupid.
Reading is nothing without understanding.You might think i didnt read the gcc manual, didnt done any research, but i did.
*snicker*It might not be as solid as it should be...
/me pointing at a5498828 with a thumb over his shoulder: "Who gave that guy too much to drink?"
Thanks, that made my day.I am currently also trying to find answers, found 1 (-nostdlib remove bload)...
You're great. Please, continue....but i still dont know how do 'compile without linking' or '-march=8086'.
(Hint: GCC supports IA-32 aka x86. It does not support 286 or 8086. If you think that makes it a bad compiler, go right ahead. You've come to lots of strange conclusions already, that one more won't matter much.)
Every good solution is obvious once you've found it.
Re: c, producing code
@ a5498828:
Just to make that clear, as soon as you get rid of your attitude problem, I'd be perfectly willing to help you.
Actually, I am trying to help you, before you hurt yourself... Or Combuster finds this thread.
Just to make that clear, as soon as you get rid of your attitude problem, I'd be perfectly willing to help you.
Actually, I am trying to help you, before you hurt yourself... Or Combuster finds this thread.
Every good solution is obvious once you've found it.
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Re: c, producing code
@a5498828
Since you did not get it to start off with, I must inform you that OS development is for Advanced programmers.
From what I can see from your post (apart from a blatant disregard to the rules of language), is that you are not an advanced programmer.
My suggestion is to go away and read C tutorials and documentation, understand them, then decide if you have enough skill to attempt OS Dev. (hint, if you don't know how pointers work, you're not ready)
@everyone else
This made a boring day thoroughly bearable (along with another first post with some real intelligence in it)
Since you did not get it to start off with, I must inform you that OS development is for Advanced programmers.
From what I can see from your post (apart from a blatant disregard to the rules of language), is that you are not an advanced programmer.
My suggestion is to go away and read C tutorials and documentation, understand them, then decide if you have enough skill to attempt OS Dev. (hint, if you don't know how pointers work, you're not ready)
@everyone else
This made a boring day thoroughly bearable (along with another first post with some real intelligence in it)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Re: c, producing code
Just took the time to read some of my very first posts, or at least as far back as I could go (didn't quite look like a genuine first post) and suddenly I don't feel so cocky any more
This was supposed to be a cool signature...
Re: c, producing code
Hello,
If you want to produce code specifically for 8086, try an appropriate toolchain -- ie, Turbo C, for example.
If you want to stay with ASM go for it - no one is forcing you to use C. A lot of developers choose C over ASM for a number of reasons; I would expect any experienced C developer would know these reasons.
Dont confuse a language with a toolchain. C doesnt produce any code; the toolchain does. There are C toolchains capable of producing 16 bit, 32 bit, and 64 bit code. Saying that C cant produce 16 bit code is wrong for these two reasons.Im trying to set 8086 cpu, i want code for it.
If gcc cant do that, its game over for it, i will always look on c code as inferior one, and treat people using it accordingly.
From what i searched, it cant even make 16 bit code (no prefixes).
If you want to produce code specifically for 8086, try an appropriate toolchain -- ie, Turbo C, for example.
If you want to stay with ASM go for it - no one is forcing you to use C. A lot of developers choose C over ASM for a number of reasons; I would expect any experienced C developer would know these reasons.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
Re: c, producing code
Besides, the code generator for gcc has been written by people like you and me. There is no big company that can be blamed for not generating 8086 code. I'd suggest you take up the task of retargeting gcc for 8086 16 bit code
Re: c, producing code
GCC has been written by companies like Red Hat and Cygnus. but it's not their fault that they don't want to write and maintain something they aren't interested in.salil_bhagurkar wrote:Besides, the code generator for gcc has been written by people like you and me. There is no big company that can be blamed for not generating 8086 code. I'd suggest you take up the task of retargeting gcc for 8086 16 bit code
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: c, producing code
Try PCC for adapting an existing compiler
Re: c, producing code
Ok, ive decided to stay with asm, but use a lot of macros.