How does computer code work?

Your question can also be viewed on a deeper level.How does the inner workings of the CPU work? The famous John von Neumann

in 1945 described the “von Neumann” model on which almost all computers have been based since then:

The most important aspect of this model is that both instructions and data can be found in the same memory.

Computer code (machine programs) consist of a series of machine commands (such as a recipe) in successive words of memory. The ‘Control Unit’ of the processor has an important register: the ‘Instruction Pointer’ also abbreviated as IP. At the beginning of running a program, the IP points to the memory address of the program’s first command. The ‘control unit’ gets the word from memory to which the IP points and “interprets” this word as a command – that is, the word is usually used in an action such as “load (hole) date from memory to the accumulator (LDA)” or “add date from memory Accumulator (ADD)” and a data address.The data address determines where the date for the action comes from.The actual execution of the command usually takes place in the ‘Arithmetic/Logic Unit’ between the accumulator and the contents of the addressed data store word. Normally, after executing the command, the content is incremented from the IP to the address of the next command in memory, which is then fetched to the ‘Control Unit’ as the next command. A special action is the Jump (JMP) command, whose address part is loaded into the IP as the next command. This will retrieve the next command from another part of the program. Other commands are conditional jumps, where the address of the next command depends on the contents of the accumulator (greatly simplified). A final type of command is the Input/Output commands. Here, the contents of the accumulator are usually sent to or from the outside world.

An important extension of the Neumann model is the interrupt system.When a critical input/output is finished and needs the CPU to continue, the running program is interrupted (interrupt). Before the next command is executed, the contents of the IP’s are stored and overwritten by the address of an “interrupt service program”. This is the next time the Interrupt Service program runs. As the last command of each interrupt service program, the stored address of the interrupted program is loaded into the IP, which is then executed as if nothing had been.

An important analogy is cooking.Cooking recipes have consecutive commands, conditional jumps that generate loops, input/output in the oven and interruptions when the phone or egg clock rings.

I hope this simple representation gives a sense of how computer code is executed as machine commands in the CPU.Computer code in higher programming languages is either translated by a ‘compiler’ into machine commands, which can then be executed as a program in memory, or they are interpreted directly by an ‘interpreter program’. An ‘intepreter’ is an emulation of a CPU whose commands are the words of the higher language, which are then executed (interpreted) in order or jumps, just as in the hardware CPU.

Leave a Reply