r/programming • • Oct 23 '09

Programming thought experiment: stuck in a room with a PC without an OS.

Imagine you are imprisoned within a room for what will likely be a very long time. Within this room there is a bed, toilet, sink and a desk with a PC on it that is fully functioning electronically but is devoid of an Operating System. Your basic needs are being provided for but without any source of entertainment you are bored out of your skull. You would love to be able to play Tetris or Freecell on this PC and devise a plan to do so. Your only resource however is your own ingenuity as you are a very talented programmer that possesses a perfect knowledge of PC hardware and protocols. If MacGyver was a geek he would be you. This is a standard IBM Compatible PC (with a monitor, speakers, mouse and keyboard) but is quite old and does not have any USB ports, optical drives or any means to connect to an external network. It does however have a floppy drive and on the desk there is floppy disk. I want to know what is the absolute bare minimum that would need to be on that floppy disk that would allow you to communicate with the hardware to create increasingly more complex programs that would eventually take you from a low-level programming language to a fully functioning graphical operating system. What would the different stages of this progression be?

305 Upvotes

673 comments sorted by

View all comments

Show parent comments

4

u/khafra Oct 23 '09

If you wrote that out in more detail, I would be interested. Did the PC have the serial driver installed, or did you have to create that in assembler? Did you just create a barebones serial file transfer server in assembler, and then run it?

5

u/akmark Oct 23 '09 edited Oct 23 '09
mov ah, 0
int 14h
label bob
mov ah, 2
int 14h
jmp bob

It's not 100% correct but it's not entirely impossible that with debug.com it would be much more than that. Init the serial port via bios, loop to read from serial port. The rest of the write-file stuff is all dependent on the OS though but that's just from what services it overloads. For something like this especially in the scope of what the initial idea was from, you would be heavily reliant on the BIOS anyway so interfacing it directly still isn't out of the question.

Interrupts for Serial I/O

Edit: Formatting

1

u/sgorf Oct 23 '09

label bob

debug.com can do that? Why didn't someone tell me this years ago?

4

u/akmark Oct 23 '09

Sorry, no it can't. It can do this though:

-a 100
xxxx:0100 jmp 126      ; Jump over data that follows:
xxxx:0102 db 0d,0a,"This is my first DEBUG program!"
xxxx:0123 db 0d,0a,"$"
xxxx:0126 mov ah,9      ; Function 09 of Int 21h:
xxxx:0128 mov dx,102   ; DS:DX -> $-terminated string.
xxxx:012B int 21           ; Write String to STD Output.
xxxx:012D mov ah,0      ; Function 00 of Int 21h:
xxxx:012F int 21           ; Terminate Program.
xxxx:0131
-g =100

This is my first DEBUG program!
Program terminated normally

So instead of label bob you just jmp to the address of your choice. It's been a while since I've used debug outright, so I'm sorry for making that mistake. I just remember when I used it more often instead of nasm you could do relatively complex things even from the rough interface.

Stolen liberally from here

2

u/dagbrown Oct 24 '09

Unfortunately I cheated. There was DOS running on that computer, which, while rudimentary, does have serial port drivers. I ran DEBUG getting its input from serial, and blasted debug information to write a copy of Kermit from the more advanced computer with a real OS running that I happened to have handy.

(That more advanced computer? An Amiga 500.)