Science Writing an OS in 8086 Assembler

n72.75

Move slow and try not to break too much.
Orbiter Contributor
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 21, 2008
Messages
2,696
Reaction score
1,355
Points
128
Location
Saco, ME
Website
mwhume.space
Preferred Pronouns
he/him
I've just recently got back into 8086ASM and have decided to write a simple kernel that can accept commands from a shell, and schedule and execute binaries.


Just as a refresher, I wrote a simple Helloworld boot program:

Code:
#make_boot#

ORG 7C00h

PUSH CS
POP DS

LEA SI, msg

MOV AH, 0Eh

print:  MOV AL, [SI]
        CMP AL, 0
        JZ done
        INT 10h
        INC SI
        JMP print

done:   MOV AH, 0
        INT 16h
        
MOV     AX, 0040h
MOV     DS, AX
MOV     w.[0072h], 0000h

JMP     0FFFFh:0000h

new_line EQU 13, 10

msg DB  'Hello World!'
    DB  new_line, 'Press the any key to reboot', 0

Obviously, this is just a minimal, text printer but it provides anyone with no assembly experience, with a look at the code.

I would love it if we could make some sort of community project out of this.
 

tl8

Addon Developer
Addon Developer
Tutorial Publisher
Joined
Oct 16, 2007
Messages
3,645
Reaction score
25
Points
88
Location
Gold Coast QLD
Good luck with that. Assembly is ok for some things, like real time data processing, but writing an OS is out of my league.
 

Artlav

Aperiodic traveller
Addon Developer
Beta Tester
Joined
Jan 7, 2008
Messages
5,790
Reaction score
780
Points
203
Location
Earth
Website
orbides.org
Preferred Pronouns
she/her
I've just recently got back into 8086ASM and have decided to write a simple kernel that can accept commands from a shell, and schedule and execute binaries.

...

I would love it if we could make some sort of community project out of this.
Make sure you realize the scale.
It may take a decade of intermittent learning and programming to get even something as simple as that is OS development - http://forum.osdev.org/viewtopic.php?f=2&t=21536

Also, 8086 code is really long obsolete, what use can such project have?
 

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,218
Reaction score
1,566
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
:goodposting: +1 to what Artlav said. Given that modern computers have 4GB+ of RAM, it really doesn't make sense to write a new OS in pure assembly language unless you're just doing it for fun. In the old days of DOS, CPU power and memory was at a premium and so the speed and small size of pure assembly language made sense for operating systems. That is no longer the case, however.

I've programmed a fair amount of 80x86 assembly language in my time (including writing device drivers professionally and developing a pure 80386 assembly language text/binary file viewer in the 90s), and developing and debugging assembly code is a lot more work than using some higher-level language such as C. In these modern times assembly language is best suited at targeted individual functions that you need to be highly optimized, or for certain device drivers where low-level access to the hardware is necessary. Even there, however, C is a good compromise between low-level hardware access, execution speed, and maintainability.

However, if you're just doing it for the fun of learning/using 80x86 assembly language, go for it! :)
 

n72.75

Move slow and try not to break too much.
Orbiter Contributor
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 21, 2008
Messages
2,696
Reaction score
1,355
Points
128
Location
Saco, ME
Website
mwhume.space
Preferred Pronouns
he/him
I actually have some old 8086 chips and other assorted hardware of the era and I was planning on running said OS on this hardware.


But yes, I was just doing this for fun.
 

thomasantony

Member
Joined
Nov 19, 2007
Messages
355
Reaction score
6
Points
18
Location
USA
Website
www.thomasantony.com
Well, you can write OSes in 32-bit or 64-bit x86 ASM ( so no segments and crap like that ) and get them to boot on modern day computers.. There is one made entirely using ASM ( http://www.menuetos.net ) . I was once a big fan of Win32ASM programming ( masmforum.com http://win32assembly.online.fr/tutorials.html ), in fact you could say I got into programming through that. Also check osdever.net. There are a few resources on pure assembly OSDev.

I have tried making one myself ( some 4-5 years ago ) and got as far as FAT12 drivers ( it was on a floppy disk ... ) and keyboard drivers. Memory paging etc. drove me nuts. But it did run in 32-bit mode and accept some rather rudimentary commands.

I tried once again later on with a combo of GCC+Asm. But still got bored of it ... once i reached the part of implementing malloc() etc. But one thing is for sure, it will teach you a LOT about the internal workings of the PC.

All the best in your endeavors :)

--
Thomas
 

cinder1992

Random failhurricane.
Addon Developer
Tutorial Publisher
Joined
Jul 5, 2009
Messages
350
Reaction score
1
Points
0
Website
cinder1992.blogspot.com
are you using TASM or NASM? I've also been writing an OS, but I prefer to stay away from TASM as much as I can, NASM is straightforward.

oh, and if you want to get SERIOUS, I suggest you write it in protected mode, that's FUN[/sarcasm].


just FYI, the text mode VRAM offset is 0xb8000.
 

thomasantony

Member
Joined
Nov 19, 2007
Messages
355
Reaction score
6
Points
18
Location
USA
Website
www.thomasantony.com
are you using TASM or NASM? I've also been writing an OS, but I prefer to stay away from TASM as much as I can, NASM is straightforward.

oh, and if you want to get SERIOUS, I suggest you write it in protected mode, that's FUN[/sarcasm].


just FYI, the text mode VRAM offset is 0xb8000.

But really, working in protected mode is not as much of a pain as working with segments and sh*t in real mode. When I worked on my small OS project, one of the first things I did was to make it go to protected mode. Of course, video etc. becomes a little tough after that as you can't directly write to 0xb8000 ( I don't remember though .. if that was the case .. ). But its still pretty ok if you know your way around. Getting as far as keyboard driver, basic text-video driver and filesystem is possible with ASM.

And yes, NASM/FASM are the best options for ASM based OSDev.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,628
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Of course, video etc. becomes a little tough after that as you can't directly write to 0xb8000 ( I don't remember though .. if that was the case .. ).

You can - you only need a segment descriptor that points to that physical memory location. At least from the 80386 on, this isn't too hard.
 
Top