Enter the Keyboard
Someone watching over the programming process got the brilliant, but today seemingly obvious, idea of attaching a keyboard to the computer. Instead of typing those 1s and 0s, the programmer could type names associated with each instruction in the machine language. Therefore, the previous few instructions might look something like this:
ADD A, 6 MOV A, OUT LOAD B SUB B, A :
These commands are cryptic, but they are a lot easier to remember than the 1s and 0s. The words are called mnemonics, which means the words are easy-to-remember abbreviations for the instructions. ADD A, 6 is a lot easier to remember when you need to add 6 to the value of a memory location named A than is 01000110.
Of course, the computer could not understand the mnemonics, but a translator program called an assembler was written to be the go-between for the programmer's mnemonics and the 1s and 0s to which they were translated. Figure 3.2 shows how the assembler acts as the go-between for the human programmer at the keyboard and the machine. A huge leap forward was made when the assembler language became the primary means by which programmers entered instructions into the computer. This second programming language (the first was the native 1s and 0s machine language) enabled much faster program development. The software revolution began just a few years after the computer hardware was born.
Figure 3.2 The assembler translates mnemonics into 1s and 0s.
The keyboards used with the early computers were not attached to the machines as directly as they are today. Often, programmers would use a card-punch machine. These machines had keyboards, but the typing produced punched holes in computer cards. Then the cards were read into the computer's memory. You may have seen these punched cards, but they are rarely used today. Online terminals (screen and keyboard combinations) are much more efficient than card-punch machines, and you won't rearrange a thousand-line program on a terminal as easily as you would if you dropped a box of punched cards.
These first two programming languagesmachine language and assembler languageare called low-level programming languages. The computer doesn't need to translate much to convert assembler to machine language because each assembler instruction has a one-to-one correlation with a machine-language instruction (a machine-language instruction may take more than one byte of memory, though). Low-level languages are rarely used today due to the nature and efficiency of high-level programming languages (C++ and Visual Basic, for example).
Machine language programming is cryptic. Today's machine-level code is more powerful than before. For instance, there are machine-language instructions to perform multiplication and division, whereas computers of the first and second generation rarely had that power at the machine level. Programmers had to write machine language programs to perform such mathematical feats.
Until today's fast computers arrived on the scene, whenever a program's speed and low overhead were critical in the past, programmers often used assembler and machine language instead of a higher-level language such as COBOL (you'll learn about high-level languages throughout the rest of this and the next chapter). It is more difficult to learn a low-level language than a high-level language, and it takes longer to program in the low-level languages, but for some applications the assembler level is the only place to be.
Quite often, programmers would combine a high-level programming language such as C with some assembler language routines, speeding up the critical processes while keeping the more readable (and maintainable) high-level language for the majority of the program.