• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

A question I won't understand the answer to.

Nov 17, 2019
13,315
7,885
136
I don't know the first thing about coding. I've done a small amount of HTML and a few decades ago I played with Basic for a few minutes. Never even started with Fortran, Cobol, Python or anything since.

What I never got my head around is this ..... all of those languages are using letters and numbers the way we write them on paper, but what makes the chips understand them? How does the machine know to turn a character dark and heavy when it sees the <B> or <strong> tag? How does it know that FF0000 means to make the display red?

Yes, that's an oversimplified way of asking the question, what is the underlying set of information to tell the chips how to align the 0s and 1s?
 

purbeast0

No Lifer
Sep 13, 2001
53,643
6,527
126
Well I am a coder and have been doing it for over 20 years now, and I too don't completely get it either lol.

At a very "high level" (yes pun intended), the languages you are talking about are also high level. It then gets translated to instructions that the computer understands through various methods and turned into the low level assembly language that the computer "understands".

But really, other than that, I too don't really know anymore than that. Nor do I need to know more than that for my field. I would guess that the colors are basically stored in some sort of hashmap though so that it just looks up the color based on the hex value.
 

sdifox

No Lifer
Sep 30, 2005
100,363
17,924
126
That is high level language meant to make it easier for humans. Every thing programmed eventually end up being machine code after the compiler/interpreter/assembler is done translating it.

Read this, it should help you understand

 
Last edited:
  • Like
Reactions: BurnItDwn

dank69

Lifer
Oct 6, 2009
37,374
33,017
136
What purbeast said except when it comes to colors the hex values are color values, there isn't a hash map I'm aware of. FF is the hex value 255. F is 16 (15 in 0 index) so 16x16=256 and then minus 1 because the array goes 0 to 255 instead of 1 to 256. Computers work with 1s and 0s not 1s and 2s. So then the first two hex chars specify red level 0 to 255, second two hex chars specify green level and last two specify blue. FF0000 = 255,0,0 which tells the computer to light up the red pixel all the way and turn off the green and blue pixels completely.
 
  • Like
Reactions: purbeast0

VirtualLarry

No Lifer
Aug 25, 2001
56,587
10,225
126
OP, it's called "Parsing". I've written domain/language-specific code beautifier programs, and an embedded macro processor / expander, so I have some experience here.

Think of the way that humans process visual signage while driving. That's kind of like how parsing works. The parser take a stream of data (usually plaintext source code), and looks for "signs" in it (as the "car" "drives" down the road / parses through the code stream), and then the parser has a specific bit of code attached to each sign-recognizer, much like we learn the appropriate things to do at different traffic signs, based on "the rules of the road". That's basically akin to the language specification used by the parser.
 
Last edited:

PowerEngineer

Diamond Member
Oct 22, 2001
3,606
785
136
Well, back in those often referenced "good old days" of minimal computing power there was a discreet step of "compiling and linking" that took the lines of code composed by the user and translated them into an "executable" consisting of strings of 1's and 0's that were instructions that the computer could actually act upon. Now that we have so much computer power at our fingertips, much of this translation (and error checking) is happening "on the fly" as code is being written (and perhaps unappreciated) - but it is still happening.
 

Red Squirrel

No Lifer
May 24, 2003
70,603
13,810
126
www.anyf.ca
From my basic understanding the way cpus, microcontrollers etc work is they have various instructions, and memory locations (registers). You can perform actions by calling instructions and putting specific data in a specific register. An instruction ca be something like add, multiply, divide, if the computer is just a calculator, but there can are 100's if more on modern processors. Using this simple concept you can make the computer do basically anything. So when you're coding, your code gets translated to a bunch of lines doing just that which is the machine code. It's calling instructions and putting data into registers and performing tasks with it. I'm simplifying it by a lot mind you, it gets complicated when running code within an OS as really the OS is handling most everything.

You can go even deeper than that if you want to get right down to the transistor level, as everything is basically on and off states and each cpu pin has a function such as talk to the pcie bus, ram, etc.

At least that's my basic understanding of it. Never gotten too deep into the low level workings.
 

Paperdoc

Platinum Member
Aug 17, 2006
2,499
374
126
All of the high-level languages that we use (because they look like English and we can read and understand) actually exist because each is defined by a Compiler. A Compiler is another program that has a range of defined words it can recognize, and a pre-set whole routine for each word that can convert that into the hexadecimal machine code the computer circuits actually can execute. It also has a whole bunch of rules of syntax - how words and symbols and numbers can be deciphered into smaller steps that each can be translated into machine code. Then it has all sorts of programmer aids that can determine that a certain input phrase cannot be understood for translation, so it displays instead an error message the user may be able to understand to use in correcting the input. The final output of a Compiler is a complete string of machine code the computer can execute, written as an executable file. The computer's Operating System, using a small range of commands its own Command Interpreter can understand, can load such an executable file and start it running.

A Compiler, by its fixed ability to respond to a limited number of command words, defines the language. BUT it also MUST be written for a particular CPU processor which has its own fixed set of recognized operations.

In the old days, the LINK step was the way that a programmer could specify that a source code set also required the use of some other pre-compiled subroutines in a library file. This step ensured that the required routines were found and added to the executable file before the entire setup was actually started. AFTER that, the GO step actually initiated running the final group of code. The comparable structures today are the .dll files - named for Dynamic Link Library - which can be used by executable code as sources of subroutines, provided that are made available to that code.

In the earlier days of desktop microcomputers it was common to have the Operating System also include what is known as an Interpreter - VERY often a BASIC interpreter - which again defines the language and must be customized to the processor and other hardware in the system. In this system there was no Compiler or Linker. High-level code (in BASIC, for example) was written and stored as text code exactly as written. When the OS command to RUN was executed, it started the Interpreter. That tool read the text file one line at a time, translated it into machine code, executed that code, then returned to process the next line. This process makes the machine do a lot more work for each line of original code (compared to pre-compiled code) and slows things down, but it makes interactive code development and debugging easier. Most interpreters have no simple way to access external pre-compiled routines in libraries, but one uses subroutines in the main code instead. In some cases, actual Compilers were also developed for some interpreter-based languages. AFTER the complete code was developed and debugged under the Interpreter system, that same code file could be run through a compiler to generate an executable file that could be stored and then run much faster (with no line-by-line interpretation steps) under the OS.

If you were to use some tool to examine the string of hexadecimal values stored in a section of RAM where an executable file is stored, it would appear to almost everyone as meaningless. But each value represents either an instruction, an address in RAM, or a data value. People who actually do this, however, normally use a tool called an Assembler. It can display the hexadecimal code from a section of RAM, and alongside that the Assembly language symbols for the meaning of the instruction codes. Used correctly, this tool allows one to read exactly what the compiled code set does, and even allows one to write in the Assembly language. However, that requires a very complete understanding of how computers do their work - in particular, the exact processor and system you are working with - and is VERY slow and VERY poor for debugging, so virtually nobody does this any more. Machine code accessed this way is so complex and different from a high-level language that it is virtually impossible to translate it back into any high-level language. The very best that might be done with enormous work would be to understand absolutely every action of the entire executable file under all circumstances, and then re-write a new set of high-level code to produce the same results. That's a HUGE reverse-engineering task. In almost any case, a different route would be taken to reproduce the work of an established executable.
 
Last edited:

Paperdoc

Platinum Member
Aug 17, 2006
2,499
374
126
Red Squirrel said, "guessing it was written directly in machine code". Exactly. In the late '60's I knew a young programmer who solved a major problem by writing in machine code. The University's IBM System 360/50 mainframe had a bad incident - really bad design by another programmer caused it to wipe clean all its files on system disks, so they had to back up everything from tapes. BUT the routine in the OS was faulty and it could not read the tapes! Friday afternoon, and all hands on deck!! What to do? After discussions a decision was made to try writing in machine code a new read routine, hoping that they had identified the error in the data on tape and could read around that. So Howard wrote the code, and it worked! First guess was right! (It was said that, when Howard wrote using a card punch machine, code just flowed out of his fingers.) They spent most of the weekend backing up from the tapes, and everything was working fully by Monday morning.

I always wondered about this incident - and it WAS real, I was there. There were a LOT of systems across the world using basically this same OS on these machines, and nobody prior to this had sent out an alarm that the backup tapes contained errors that made them unreadable?
 
  • Like
Reactions: lxskllr

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,698
4,660
75
Here's a fun one... How did they compile the first compiler? :eek:

(guessing it was written directly in machine code)
It's compilers all the way down! :p Just kidding...mostly.

There are three ways to parse computer code. There's the interpreter, which is like reading a foreign language and pushing the matching buttons on a machine without understanding it. There's the compiler, which is like translating a book from a foreign language, then reading it. (I don't know all the details because I didn't take that compiler construction class.) And then there's the JIT compiler, which is like a live translator, like at the UN. A translator can notice somebody's saying a whole phrase, like "cuesta un ojo de la cara", and translate that properly to "it costs an arm and a leg", not the literal "it costs an eye of the face", which is harder to understand.

These days a lot of CPU machine code instructions are interpreted or JIT-ed into a more basic microcode. But older, simpler CPUs didn't do that.

Any computer program (excluding peripheral interaction) can be compiled for or interpreted by a Turing machine. That's one of the simplest general-purpose computers you can conceive of. There was once a fun game that demonstrated something similar to a Turing machine, but it was written in Flash. The developer claims another version is coming next year.
 

sdifox

No Lifer
Sep 30, 2005
100,363
17,924
126
So compilers/interpreters always have to be running to get the code to work?

Compilers take you code and create a machine code executable and that is what you run. Once the exe is created, compiler is out of the picture. Interpreter on the other hand runs your code without creating the exe.
 
  • Like
Reactions: paperfist

paperfist

Diamond Member
Nov 30, 2000
6,539
287
126
www.the-teh.com
Compilers take you code and create a machine code executable and that is what you run. Once the exe is created, compiler is out of the picture. Interpreter on the other hand runs your code without creating the exe.

Even compiled code is still not faster then assembly language code, right?
 

sdifox

No Lifer
Sep 30, 2005
100,363
17,924
126
Even compiled code is still not faster then assembly language code, right?

No, compiled code is in machine code, faster than assembly. A good assembly coder could create code that is faster than what the compiler creates.

You don't know what is fun til you are trying to shave 20ms off the execution time of your 68k assembly code for real time sensors so it can fit in the trasmit window.
 
Last edited:
  • Like
Reactions: paperfist

purbeast0

No Lifer
Sep 13, 2001
53,643
6,527
126
No compiled code is in machine code, faster than assembly. A good assembly coder could create code that is faster than what the compiler creates.

You don't know what is fun til you are trying to shave 20ms off the execution time of your 68k assembly code for real time sensors so it can fit in the trasmit window.
As a dev myself, that actually does sound fun lol. I love trying to make things more performant.
 

sdifox

No Lifer
Sep 30, 2005
100,363
17,924
126
As a dev myself, that actually does sound fun lol. I love trying to make things more performant.

electronic canaries for mines. The server poll the sensors so you have a transmit window and you have to send in that window or the evac alarm goes off :eek:
... this was in the 90s, was working for an engineer that refuses to let us use Borland's C Math library. His reasoning is we didn't write it so we didn't know if it worked. I said, "I trust Borland more than myself".
at the end I gave up and gave the project to the more senior coder xd Took him a month to find 20ms.
 
Last edited:

nakedfrog

No Lifer
Apr 3, 2001
62,838
19,056
136
Red Squirrel said, "guessing it was written directly in machine code". Exactly. In the late '60's I knew a young programmer who solved a major problem by writing in machine code. The University's IBM System 360/50 mainframe had a bad incident - really bad design by another programmer caused it to wipe clean all its files on system disks, so they had to back up everything from tapes. BUT the routine in the OS was faulty and it could not read the tapes! Friday afternoon, and all hands on deck!! What to do? After discussions a decision was made to try writing in machine code a new read routine, hoping that they had identified the error in the data on tape and could read around that. So Howard wrote the code, and it worked! First guess was right! (It was said that, when Howard wrote using a card punch machine, code just flowed out of his fingers.) They spent most of the weekend backing up from the tapes, and everything was working fully by Monday morning.

I always wondered about this incident - and it WAS real, I was there. There were a LOT of systems across the world using basically this same OS on these machines, and nobody prior to this had sent out an alarm that the backup tapes contained errors that made them unreadable?
Frankly, I am not in the least bit surprised. I've encountered plenty of redundant/backup systems that failed to actually live up to the job when the shit hit the fan. And plenty of times when the urge to get the redundancy working properly fades out once normality has been restored...