Introductions
so if you're like me coming from a non-traditional route into tech, have been and worked in the industry for a few years, I'm sure it has crossed your mind too, wondering how things really work under the hood, beneath your for-loops, your if-else statements you write with JS or so, or just having that thought to get to get your foundations right and to see and understand the level of abstractions there is to what has gotten you to comfortably write some higher level language, then you definitely have felt exactly like I have(at least with respect to programming though), which prompted me to start studying this book. Getting on this piece of material sparked even more curiosity to understand systems properly, even so, to get to understand the language C, which I had taken a crash course on YouTube from Giraffe Academy, and looked at references and pointers sparsely and kinda loosely understood it from a higher level perspective, and now I seek to learn to appreciate the work that is being done extensively in the shadows while the programmer appreciates what s(he) sees on the screen. I seek to explain this book from a Non-CS Grad's perspective, if that is actually a thing though, and to put out thoughts that I found resonated with me and shone the light bulb to my understanding. so let's begin :).
Chapter 1 began with understanding from a vantage point, the different parts and systems involved in how a simple hello world program in C is being compiled from the time the program is run to the time it is printed out to the screen. I think this chapter is summarized with this one depiction of higher levels of abstractions below:
Information is bits + context:
this section quite explained how every thing within a source file is just bits of information, and used the hello.c source file which is a text file because it represents info as texts to show how each character in the file has an integer which is a byte representation of the character attached to it. This is called the ASCII standard of representation.
Programs are translated by other programs into other forms:
your code needs to be translated from a human readable format to that which the machine can understand(machine level code or executable object program) by a compilation which consist of these 4 phases of code transformation;
i) preprocessing phase:
ii) compilation phase:
iii) assembly phase:
iv) linking phase:
understanding these phases in the compilation system is crucial to optimizing program performance, understanding link time errors, and avoiding security loopholes. i'm yet to understand in detail what these are, will deep dive as i explore more in the next chapters.
Processors read and interpret instructions stored on memory:
before getting to the processors, first our hello world program that has been compiled by the compilation system from our hello.c file to an executable object program(eop), is stored on the hard disk, ready for retrieval when we call the file, /hello at say, a terminal such as the shell terminal. so before we understand how our hello world program is run, we first need to understand the hardware of our system.
a typical hardware system is made up of:
i) buses: which are a collection of electrical conduits that carry information from one part of the system to another in the form of bytes or words. i understand now why a machine is labeled either 32 bits or 64 bits OS, this means that that system can at a point move either 4 bytes or 8 bytes of information through its buses at any given time.
ii) i/o devices: these are our keyboards and mouse we use to input data, and display(e.g, screens to output data), and disk drive for long term storage.
iii) main memory or RAM: they are a collection of what they call DRAM(dynamic random access memory) chips that act as a temporary storage device. our compiled program when moved from the hard disk to be processed by the cpu, is first stored here.
iv) processor: interprets instructions that are stored on main memory as eop(executable object programs). there are a few of these simple operations that a processor does, and are centered around alu(arithmetic logic/unit --new concept to me as well, i think it has something to do with math operations) and register also called program counter(pc). the pc, points to a specific address in main memory where an instruction is, performs an operation dictated by the instruction, and then updates the pc to point to the next instruction. as long as your personal computer is switched on, this is what the processor does all through -- executing instructions.
Running our hello program
when we type the characters/hello in our shell command line, the shell reads each and everyone of the characters and registers them, and then stores it in the shell's memory(buffer). after hitting enter on the keyboard, the shell takes this as that we have finished typing, then it copies the data and executable hello file stored in disk to memory. this is achieved by a technique known as (direct memory access) DMA, without passing the processor. when code and data of the hello file are found in the main memory, the processor can then starts doing its executive job by running execution on the executable object programs in the hello file.
Caches Matter -- Indeed
ideally, processors would take a longer time to read files in the hard disk than they would in the main memory, similarly, they would take an even shorter time to read data on register files than they would from main memory. so scientists sought out to fill out this "processor-memory gap" as they called it, by introducing cache-memories devices which they serve as temporary areas for holding information that the processor would need in the future.
in the figure below, we see how these caches form some sort of a hierarchy, the l1, and l2 caches are made with a tech known as the static random access memory(sram) but there even larger and more powerful systems which have three levels of cache, l1, l2, and l3.
i'm learning that, being aware of the benefits of caches can be truly useful when writing application programs, because you can exploit them to improve the performance of your programs.
Abstractions upon abstractions
just like we write apis, which contain methods that call other methods and so on, i learnt that scientists found a way to abstract the hardware system by introducing a layer called the OS(Operating System). this acts a way to protect the hardware from misuse, and to provide a simple uniform mechanism that apps can manipulate low level hardware devices.
there are 3 layers to the O.S, the processes which are the highest level of abstraction in the OS, they abstract the processors, main memory, and I/O devices, followed by the virtual memory which abstracts the main memory and I/O devices, and the last which is the files which abstract the I/O devices.
processes give an illusion to a running program that it is the only program running on the entire system. so it creates this illusion that this program has exclusive access to the processor, memory and i/o devices.
this brings me to a next big term, concurrency which simply means instructions of one process are interleaved with the instructions of another process. giving the system an edge to executing multiple programs at the same time.
this section warrants a deep dive later, as we will keep on exploring further on it.
Summary
so, in summary we have this program which we want to run, the hello program, which begins as ASCII text and then translated by compilers and linkers into binary executable files or executable object programs(eop).
processors and interpret read these eop that are stored in the main memory.
as computers spend most of their time moving data between memory, i/o devices, cpu registers, storage devices are arranged in a hierarchy, with the cpus at the top, followed by several levels of hardware cache memories, dram main memory, and storage disk. storage devices that are higher serve as caches for devices that are lower in hierarchy. programmers can use this to their advantage and optimize for performance their C programs by understanding and taking advantage of the memory hierarchy.
OS acts as the intermediary between the application program and the hardware.
Image Attribution
The images used in this article are sourced from external platforms and are not my original creations. They are included purely for educational purposes to illustrate concepts from the book "Computer Systems: A Programmer’s Perspective." All credit for these images goes to their respective creators or uploaders.
Final Thoughts
that's it folks, please share your ideas with me in the comments section and leave any thoughts for correction as well, as this purely is for learning purposes. thank you!





Top comments (2)
Thanks for sharing :)
Absolutely, Saumil. Thank you for reading!