C or asm

Programming, for all ages and all languages.
Post Reply
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

C or asm

Post by VolTeK »

i am almost finished with my current os, and have been thinking about how my future in this is going to look and how good it will be depending upon what tool i use. i have looked into 32 bit assembly, but still cant even enter protected mode (workin on it) i always get the "processor error" in virtual PC 2007, i have used every tutorial i could get my hands on, and nothing has ever worked for me, so in the mean time im leaning new things. but i want to know what programming langage is most effiecient for my 32 bit development. C or asm (i have learned alot of 16 bit asm, and learning 32bit)

any help would be appreciated,

thanks
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: C or asm

Post by neon »

I would have to say C. HLLs allows you to not worry about alot of the details involved in assembly language, and provides faster productivity rate compared to assembly language.

(oh, and congrats on your 256th post!)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: C or asm

Post by NickJohnson »

I would also recommend using C for most of a project, not only because it hides many tedious details (which is a big plus), but also because of portability - if 95% of the code is C, theoretically all you would need to port is 5% of the code to make it work on another architecture. Of course, for kernel code, a lot of it is not portable, but the higher level parts as well as everything outside of the kernel should require little modification. (IIRC) the reason C was initially so successful is because it was portable across architectures.

If you like assembly a lot, it might be a good balance to have everything non-portable (not just requiring privileged instructions or stack hacking) written in an assembly "hardware abstraction layer", which is linked to by C code that does the high level stuff that ties everything together. The point is, use assembly where it works better: I have seen assembly shorter and clearer than C for bare metal operations.

Edit: You mean congrats on 0x100 posts (or perhaps 0400?) :mrgreen:
Last edited by NickJohnson on Tue Nov 10, 2009 7:56 pm, edited 1 time in total.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: C or asm

Post by VolTeK »

then i will start learning C, it wil not be easy as learnig asm was, but ill do my best. thank u for the answer, i wasnt loking for a "u can use C and asm" i was looking for a what should i put my time more torward, C or asm, and thank u for the answer. C it is then. now if anyone could help me with my real more to protectes mode switching problem problem

@neon: thanks lol now for 512, maybe next year im barely on as it is lol

@nick: lol thanks
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: C or asm

Post by NickJohnson »

Usually, protected mode OSes use a bootloader to get into protected mode, mostly because it's a tricky operation, but also because you don't have to load anything off the disk, or even deal with the (potentially buggy) BIOS at all. I would recommend just using GRUB, but if you want to bootstrap your own kernel, there is a wiki page on the protected mode switch...
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: C or asm

Post by VolTeK »

thank u, i might be enabling the a20 at the wrong time, or loading the gdtr at the wrong time, il read carefull, and thank you for the help
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: C or asm

Post by neon »

Ghost: This might help when understanding protected mode and getting into it. If you need specific help, feel free to ask.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: C or asm

Post by VolTeK »

thank you, and i might, and i am sure i will have some questions. thank you all
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: C or asm

Post by VolTeK »

finally, in protected mode, now to learn more about protected mode memory (already know some about it) and more about 32bit assembly, id like to thank the forum, (mainly neon and nick)yes i did load the a20 and the gdt in the wrong places and had cli and sti where they shouldnt be. i think im going to leave my realmode project out and start on the realy fun stuff
Post Reply