Tuesday, February 24, 2015

BUriversity: Machine Code 101

Based on readers' topic suggestions

How do we tell computers what to do?

The central processing unit, or CPU, is the brain of any computer. It understands a very basic set of atomic instructions like "add this value to that value" and speaks only in binary -- a neverending series of 0s and 1s. In the early days of computer programming, programmers quickly came to the realization that communicating with the CPU at this level was error-prone and migraine-inducing, like the job of a cop reporting on the high-speed pursuit of a criminal whose license plate is a random mix of capital Is and lowercase Ls.

To remedy this situation, programmers relied on "layers of abstraction", taking chunks of machine code and assembling them together into human-readable instructions just slightly more understandable (called assembly language). Programmers then went up another level to languages like C, which are English-like and compiled into assembly language. Programming languages, then, are like ogres -- they have layers. If this layering concept is still hard to grasp, click on one of the buttons below to get an example in a context you are more familiar with.

This layering of abstractions continued over fifty years until today, where we have high-level languages that are so close to English prose that they sometimes read like poorly-written Twilight fan fiction. The benefit of these layers of abstraction is that a human programmer can write instructions in a language more closely related to the domain he or she is working in. Unfortunately, as languages becomes easier for humans to understand, they become more difficult for the binary-based computers to understand.

Every high-level language is eventually translated down to binary machine code before execution, since the CPU is essentially like a calculator with only 3 buttons. Thankfully, this translation is not a manual process, since a single line of code like System.out.println("Booty"); could end up being hundreds of lines of machine code.

Wouldn't the machine code need to be able to read itself as binary?

No. The machine code is just a dumb set of instructions with no processing smarts of its own. And, the CPU has a small set of instructions hardwired into it, such that there is a one-to-one mapping of every incoming machine code instruction to a CPU instruction. No interpretation or translation is happening when the machine code arrives at the CPU -- it just gets stored and run as-is. The CPU is like the bureaucrat with fifty years experience who knows exactly where to file your paperwork just by the identifying number on the form, not the summer intern who has to look up the form number in a process manual every time he sorts the mail.

Have any more ideas for future BUriversity courses? Suggest them in the comments section!

tagged as buriversity | permalink | 3 comments
day in history


Previous Post: Weekend Wrap-up


Next Post: Memory Day: Twelve Years Ago Today

 

You are currently viewing a single post from the annals of URI! Zone history. The entire URI! Zone is © 1996 - 2024 by Brian Uri!. Please see the About page for further information.

Jump to Top
Jump to the Front Page


February 2015
SMTWHFS
1234567
891011121314
15161718192021
22232425262728
OLD POSTS
Old News Years J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
J F M A M J
J A S O N D
visitors since November 2003