Amir Saniyan
Amir Saniyan

Reputation: 13759

Which C compiler should I use for creating my own simple OS?

This tutorial shows how to write my own simple Operating System:

Write Your Own Operating System Tutorial: http://joelgompert.com/OS/TableOfContents.htm


Every thing is OK, but developing language is Assembly. I want develope my simple OS with C programming language.

I want a C Compiler that convert my C source codes to Assembly sources and then I compile assmebly files with NASM.

Compiler should can create assembly files that compiled by NASM.

C source files that converted to assembly source files with GCC (gcc -S OS.c masm=intel) fails when I compilng them with NASM.

I dont use any C standard libraries even stdio.h or math.h. I want a compiler that

Which C compiler should I use for creating my own simple OS?

Upvotes: -1

Views: 1172

Answers (2)

Valarie Brega
Valarie Brega

Reputation: 37

if you want to write your own operating system in c look up Pritam Zope on YouTube. hes brilliant and has many videos on writing your own kernels and boot-loaders in c and asm. I'm also interested in writing my own operating system, Ive done some research and have decided its best to work in asm. if your interested in working in asm instead of c also check out theMike97. here is a simple boot-loader i wrote in asm encase your interested. it just prints hello world.

org 0x7c00
mov si, message       ;The message location *you can change this*
call print            ;CALL tells the pc to jump back here when done
jmp $
print:
  mov ah, 0Eh         ;Set function

.run:
  lodsb               ;Get the char
; cmp al, 0x00        ;I would use this but ya know u dont so use:
  cmp al, 0           ;0 has a HEX code of 0x48 so its not 0x00
  je .done            ;Jump to done if ending code is found
  int 10h             ;Else print
  jmp .run            ; and jump back to .run

.done:
  ret                 ;Return

message           db  'Hello, world', 0 ;IF you use 0x00
;message          db  'Hello, world', 0x00


times 510-($-$$) db 0
dw 0xaa55
~

save this code in a file called main.asm compile it with nasm -fbin main.asm -o main.bin run it with qemu-system-x86_64 main.bin

Upvotes: 0

Tony The Lion
Tony The Lion

Reputation: 63250

A compiler by definition will compiler your high level code to machine language, ie Assembler. If you want to be able to look at the Assembler, there's a GCC switch to generate assembler. Just use the -S switch when compiling your C code with GCC.

Upvotes: 2

Related Questions