Computers and Programming
Computers are consisted of electronic parts. These parts can only understand two basic states: the existence of current (state called ‘1’) and the absence of current (state called ‘0’). When we talk about 0’s (or 1’s) we actually talk about current passing (or not passing) through a pipe in the processor during a calculation it performs or about charge existing (or not existing) in a specific area of a storage device used by the computer (i.e. its RAM chip) capable of retaining such a charge. We program the computers so that we can tell them how to handle specific inputs. The input to a computer is the current passing through the pipes of the processor. The processor then processes that input according to what it is programmed to do and generated an output (again a ‘collection’ of 0’s and 1’s).
The processor of a computer is firstly programmed by its manufacturer. In particular, the manufacturer designs the circuits of the processor in such a way that the processor already knows how to act when given certain inputs. In that way, every processor has some commands he can obey to, already embedded in it. For example, consider the case of a processor which has 2 input current pipes and one output pipe that is designed in such a way that the current in each one of the input pipes is added to the other and then send the resulting current in the output pipe. That processor is already programmed to apply the ‘add’ command to its input.
The second level of programming a processor is by having direct access to its circuits after it is build and store the commands you want in its permanent memory. Intel and AMD provide big software vendors (mainly the ones which develop Operating Systems that must interact at a more low level with the processor) with access to the processors memory (via developers’ kits – including specific hardware and electronic equipment to facilitate the writing to the memory where commands can be stored to the processor), so that they can write the programs they want. For example Bill Gates and Paul Allen wrote the operating system of Altair computer in the ‘70s by toggling switches up (the 1’s) and down (the 0’s). This computer had no keyboard, just switches in its front, with which one could store programs in its memory. The output of that computer was lights flashing (the 1’s) or not flashing (the 0’s).
However no operating system is written entirely in 0’s and 1’s in that way. It is more usual for developers to write directly into the processor’s memory a program (called an ‘Assembler’) that will facilitate the developing of other programs in a more easy way: the Assembler can accept as input commands in a structured language (e.g. ‘mov ah, al’ to move the contents of the al register to the ah memory register) instead of the tedious 0’s and 1’s. This Assembler, once stored into the processors memory, can help other software developers enter their programs via the normal keyboard and store them appropriately. The conversion of the commands in the structured language the Assembler accepts as input to 0’s and 1’s which the processor can understand, is done by the Assembler without the programmer having to worry about anything. How can you write in machine language in the first place?
How can you load a program into a blank processor? Simple: talk to the processor’s manufacturer, get access (via specific hardware the manufacturer has constructed so that his processor can be programmed) to the processor and…type in your program!
Once an assembler is loaded into the processor, anyone can write…Assembly into that chip! Assembly language is a low level language that allows the programmer to do anything he wants via direct memory manipulation. With the proper commands you can store data into already specified [by whom? Don’t ask again! The answer is: by the chip manufacturer! Intel, AMD, etc…] memory segments (called ‘registers’) or into memory addresses you specify and make things work. Examples of registers are ‘ah’ or ‘al’. A direct memory address can be written in a format of AAA:DDD, where AAA is the main memory piece in which we look and DDD the displacement into that piece that leads us to the specific memory place we try to reach. The data used by an assembly program is stored into the Data Segment, whose beginning memory address is stored into the ‘ds’ register. If you want to go ‘5’ places (i.e. bits) into the data segment, just write ds:5, for example. Remember that things are highly dependable on the assembly language you use, which in turn has been developed for a very specific processor. So again: read the manual! It will solve many of your questions! Most 8088-based processors have some commands (called ‘interrupts’ because when they are executed, they interrupt the normal operation of the processor to do something else) already stored in them, which the assembly programmer can utilize by using the ‘int’ command. Please read the manual on how to do that…The purpose of this text is to show you the main underlying logic of programming so that you are not intimidated by it and not teach you programming techniques.
If you want to program in a high level language (HLL) that is object-oriented, then things are much simpler: just read the language manual, learn how you can create and use objects in that language and then…develop! Developing programs in a high level language means that you can write your source code into more elegant style, using more simple and intuitive sentences, while taking advantage of already existing power of the language itself. When you write a program into an HLL you write one command and the language takes care of the 100 steps required to execute that command into the processor. This gives the programmers more freedom to concentrate on what is really important in programming: the program’s underlying logic, its structure its algorithm. The first thing one developer has to do is think about how the program’s algorithm will work. If the design phase is perfect, then the program has a high chance of satisfying its purpose: cover the needs of its users – nothing more, nothing less. If you fail in the design, then – no matter how good your programming skills are – your program will certainly fail! Remember that.
But how do you create and use objects? First, you have to declare the class of the object. For example, if you want to create an object called ‘Blue Calculator’, you must first create and declare a class of objects called Calculator. Define the parameters of that class: the variables it will be using (i.e. the color of the calculator, the numbers which the user will enter in the calculator by pressing the buttons + the result that the calculator will print on its screen) and the methods (or functions) that the calculator will utilize in order to reach the result (i.e. functions for adding numbers, subtracting number etc).
The definition of that class will have the following scheme (independent of what the programming language you use may be):
class Calculator
{
// Variables
Number_type number1;
Number_type number2;
Number_type Result;
Color_Type Calculator_Color;
// Methods
Function Add(number1, number2)
{
Print “The result is:”, (number1 + number2);
}
Function Sutract(number1, number2)
{
Print “The result is:”, (number1 – number2);
}
} // End of class definition
Generic sample code of class declaration
(refer to the programming language manual for specific instructions on how to do that)
After you have properly declared your class of objects, you can create as many objects of that class you like and use them in your program.
For example you can create a new blue color calculator by writing a command that could look something like that:
Calculator my_calculator = new Calculator(Blue);
You can then use the member-variables and member-functions of the calculator with commands like:
Integer no1 = 2;
Integer no2 = 7;
Print “Result = ”, my_calculator(Add(no1, no2));
// this should print ‘9’ in the screen
my_calculator.number1 = 20;
Print “Result = ”, my_calculator(Add(my_calculator.number1, no2));
// this should print ‘27’ in the screen
The specific commands again depend on the programming language you use, but you get the meaning. It is all too easy:
Declare class ® Create new object of that class ® Manipulate / define parameters of the new object ® Use member functions of that object to generate the result they are designed to generate.
It may be difficult for you to grasp, but ALL programming in ANY language (C++, C#, Visual Basic, Java etc) are based on that logic. What is more, the languages themselves have some ready-made classes that you can use to develop your programs! For example, Visual C++ in the new Microsoft Visual Studio has a stored class for Buttons. To add a button to your application, you just write:
Button my_button = new Button();
my_button.color = Blue;
You don’t have to reinvent the wheel! That simple (and I think you understand what the second command does, without telling you…)! I keep repeating myself, in order for you to stop fearing the unknown realm of programming and just…start programming! The ready-made classes (or even simple functions) are usually stored in packets called ‘libraries’. Add the library you want in your program and them just use any class / function it contains.
This is the main underlying logic of all programming languages nowadays, in the year 2007. And probably for the years to come. Some languages are different than others, without any significant impact on the way you have to program. For example the programming language C is more primitive that HLLs (it stands somewhere in the middle between Assembly and HLLs) and uses mainly functions, not classes. Just open the manual of the language you prefer, read where and with which commands you declare classes in that language and do it! There may be differences from language to language (eg. ‘packages’ in Java, ‘namespaces’ in C++ 8.0 denoting large collections of ready-made classed you can add to your program etc), but the meaning is the same! EXACTLY THE SAME!
That was the programming part. The EASY part.
The MOST IMPORTANT however part of programming is also the difficult one: the part of designing the program to function properly, to serve the user’s needs. You must FIRST design the algorithm and the user interface of your program in plain paper, before you even open the computer! Only properly designed programs with good working algorithms behind them can be successful! Remember that!
Go out there, THINK of your program, DESIGN it in simple graphs and words on paper and then do the easy part! No matter how much the languages change, the fact that cleverly designed programs prevail will remain the same…