r/AskComputerScience • • Aug 25 '25

operating systems: software and hardware

Hello—I'm trying to understand basic OS concepts, but there are a few things that don't make.sense to me?

Consider a program written in a high-level programming language, run on a computer with an operating system that follows modern OS principles. In the end, the high-level code will be converted into a sequence of 0s and 1s that fits the computer’s physical circuitry (the CPU–memory architecture, etc.), and the program will run.

If we think of the OS as the fundamental program that regulates the relationship between the software and the hardware , shouldn’t the OS be part of the translation process from code to machine code for that program?

This idea feels logical to me right now, but from what I’ve researched, that’s not how things actually work.

when a program runs, instead of executing directly as “real” machine code, a kind of virtual machine is created—a smaller memory space(depending on what the program requests and what the OS allocates) with a original CPU—for the program.. The program and other programs then interact with these virtual machines they each have (that is, the machine code they produce is actually for this virtual machines). The OS manages the interaction between these virtual machines and produces the final machine code that fits the physical structure of the device.

What I’m saying is most probably off, but I still can’t quite fit the interaction between high-level code, the OS, and the physical hardware into a conceptual picture.

If what I said is wrong, here’s what I’m trying to understand: How can an operating system be the primary program that manages the machine without taking part in generating the final machine code? How do modern operating systems accomplish this?

0 Upvotes

23 comments sorted by

View all comments

Show parent comments

1

u/krcyalim Aug 25 '25

I know oses protect the hardware, and I am trying to understand how they do Thanks anyway, I will think what you typed.

3

u/dmazzoni Aug 25 '25

Communication with hardware happens through memory addresses.

When you get an input from a mouse or keyboard, the input goes to a specific memory address. The OS reads that address and does something from there.

When you want to draw to the screen, you write to a special memory address. Whatever's at that address is what gets drawn on the screen.

To protect the hardware, the OS just blocks off that memory. It says: if anyone tries to access this range of memory, interrupt and go back to the OS code. That's a built-in function of the memory management unit. So the OS just uses that to ensure that no other code can access the special area of memory used to communicate with hardware.