0

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

  • Converts C source codes to Assembly sources.
  • Or a compiler that creates flat binaries (like NASM or FASM outputs) from C sources.

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

Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
  • you will need assembler at some point... some operations will be trickier to implement in C than in assembler... (like context switching between processes) – UmNyobe May 09 '12 at 20:52

3 Answers3

1

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.

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
1

I don't have any actual experience with this, but you might want to take a look at :

Community
  • 1
  • 1
rotoglup
  • 5,223
  • 25
  • 37
0

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