processor,memory and all hardware

Hi guys so to begin I would like to say this will be a fairly long post so whoever reads this thanks for sticking with me and taking your time to read this much appreciated,

anyway I am a computer science student in my final year well I transferred to cyber security for my final year but still consider myself a computer science student as the first two years were computer science,anyway to be honest I didn't attend many lectures or labs because I have anxiety that makes travelling to the college a very daunting task it doesn't help that it's a near 3 hour commute either,I'm on medication for my anxiety and I'm coping at the moment

but I have probably missed something in between I know a little about hardware and understand how binary works and have an idea how memory works with programming languages,I have read a few books in c++ and java and none of these books sit down to explain how the computer actually handles the language and what the role of the cpu is etc

so my question is using c++ or java as the examples how does the language actually work and translate code into machine code,the cpu has it's own assembly language right?? but the cpu can only understand it's own assembly language how can the cpu understand languages such as java or c++,do the languages reside in memory? or on the cpu itself (I'm guessing not for the latter)

any help is more than appreciated

At a very simplistic level, the cpu understands only one thing - the voltage levels applied to various pins. A primitive computer can be programmed by using a set of mechanical switches to set the voltage level at those pins to either high or low.

But we can consider it in a slightly more abstract way, instead of talking of voltages, we just use the idea of 1 and 0 to represent the signal at any individual pin. A group of those 1s and 0s taken together make a binary number. This is usually the lowest level we consider, the binary numbers which the cpu can 'understand'. This is is the language the cpu understands, the language of binary numbers. It is named "machine code".

But for a human, trying to remember the meaning of different binary numbers does not come easily. So instead we use a set of short mnemonics corresponding to those binary numbers. These give us a human-readable code called "assembly language". But it is only human-readable, the cpu doesn't understand assembly language by itself.

What we can do, is to write, on paper, a short program to read simple assembly language and translate it into the binary numbers which the cpu will understand. This is all done by hand, and entered as binary numbers using mechanical switches. But - once the program is loaded, it can be used to translate code written in assembly language for us. This program is called an assembler.

It can be used to assemble itself. This is where it starts to get fun. Once the assembler is working well enough to assemble itself - that is to translate the human-readable language into machine language (binary numbers), then it can be used to create a more advanced and sophisticated version of the assembler. Thus the system 'lifts itself up by its own bootstraps'.

Beyond this point we can use assembly language to communicate with the computer, and use that to translate other more high-level languages for us, such as the C language, or many other high-level languages. But whichever language we use, the cpu is still only understanding machine code.

That's just the beginning - and doesn't really answer your question properly

Last edited on
thanks Chervil great answer,

so the actual language such as C,C++,Java reside in memory and the compiler turns this source code into assembly which the processor turns into machine code?

so the actual language such as C,C++,Java reside in memory

Not quite. When you run a compiler, the compiler is brought into memory. The compiler reads your source code and produces object code. When you run the object code, the object code is brought into memory and is executed by the CPU.

the compiler turns this source code into assembly which the processor turns into machine code?

Early compilers would produce an intermediate file containing assembly instructions, which would then be processed by a separate assembler. Modern compilers avoid this step and produce machine code directly.
This is where I'm hoping someone else will chip in with some insights.

so the actual language such as C,C++,Java reside in memory and the compiler turns this source code into assembly which the processor turns into machine code?

Well, not all languages work in the same way. There are compiled languages, There are interpreted languages. And there is Java which is kind of both.

"the compiler turns this source code into assembly which the processor turns into machine code?" Not necessarily. That is, assembly need not be involved, the compiler may handle that part of the process itself - depending on the language and how it is implemented.
assembly language is really just a human readable form of machine language. It is 'almost' one to one (that is, every assembly language instruction you see in the assembly language code printout is one machine instruction). That rule is bent a little in a few places as modern cpus can lump instructions together into 1 and similar things that older machines did not do, and a small amount of the assembly is not actual instructions but affect how the executable is built (memory model commands for example) by the assembler.

so while the compiler may generate the executable directly without the human readable assembly code file, the two things are virtually identical in terms of work done by the compiler.

the very first computers actually flipped physical switches for binary, rather than voltage reading. They were called mechanical relays, but you can literally think of them as a wall of light switches. If these things interest you, even at a hobby level, taking the first course in circuits and the assembly language class would be good learning and fun. I had to have both as such things used to be required in most computer science degrees. You can audit (attend but not get credit) for them if you are overwhelmed -- this is usually a small fee or even free for full time students.
Last edited on
Topic archived. No new replies allowed.