Книга: Introduction to Microprocessors and Microcontrollers
Basic
Basic
In Dartmouth College, USA, a simplified language was developed. It was based on Fortran and was designed as a simpler language and easier to learn. This language was called Basic (Beginners’ All purpose Symbolic Instruction Code) and first appeared in 1960 (see Figure 10.4).
Figure 10.4 The Basics
In the early days, the emphasis was on ‘easy to learn’ and ‘using a minimum amount of memory’ as memory was very expensive. These two attributes made it very useful in colleges but was largely ignored ‘in the real world’. As microprocessors appeared and gave rise to the microcomputer, the benefits of low memory requirements gave it a renewed popularity and it ‘took off’.
To save memory, Basic was designed as an interpreted language. An interpreter rather than a compiler carried out the conversion of the source code to the object code.
What’s the difference? The compiler converts the whole program into object code, stores it, then runs the program. The interpreter takes a different approach. The first instruction in the program is converted to source code and it is then executed. The next item of source code is then converted to object code and then ran and so on right through the program (see Figure 10.5). The interpreter never stores the whole of the machine code program. It just generates it, a line at a time, as needed.
Figure 10.5 The Slow ’n’ easy interpreter
The development of Basic
The explosion of microcomputers in the 1980s resulted in widespread adoption of Basic. It was used, or at least played with, by more people than any programming language before or since. More variations, or dialects, started to appear, as occurred with Fortran.
In the case of Fortran, the American National Standard Institute (ANSI) collected all the ideas together and produced the standard Fortrans like Fortran 66, 77 and 90. This did not happen with Basic and the result is now an open market with several hundred different competing, sort of compatible, Basics floating around. Most of the earlier ones have withered away leaving a few popular versions like Q-Basic, GW Basic and Quick Basic. More recently, with the virtual monopoly of the Windows operating system, a new version called Visual Basic (VB) has appeared which has features to make the generation of Windows programs much easier.
Over the years, the language has developed to provide more and more features until it closely rivals Fortran, even for calculations. Basic has shaken off its beginner’s label and is used by many professional programmers. Now that memory size is not such a problem, compiled versions are now used to accelerate the execution of programs.
There has been a series of versions of Visual Basic, VB1 to VB6 and we now have VB.Net to allow easy manipulation of Windows™ and Web site material.
Basic is very readable
It uses line numbering as in Fortran and is generally readable. Here is an example. Test out its claim to readability by guessing the outcome.
10 input A, B
20 Let C = A * B
30 Print C
40 End
On line 10, it requests two numbers A and B to be entered, possibly via a keyboard. Line 20 defines a new number C as the result of multiplying them together. Print means providing an output either onto a printer or to the screen of the monitor. The last line stops the program.
As you will remember, we always have to give a microprocessor something safe to do after it has completed a program otherwise it will start following random instructions. We can do this by sending it in a loop as we did in the assembly example to follow the same instruction over and over again or we can send it off to follow another program. The END instruction does just this. The program is returned to a ‘monitor’ program. A monitor program does the often forgotten parts of the system like scanning the keyboard to accept further instructions and is in no way connected with the screen showing the visual images.
The line numbers are executed in numerical order and any missing numbers are just ignored. This allows us to use line numbers that increase in steps of five or ten instead of ones. The advantage of this is that any forgotten instruction can be added later by giving it a new line number. For example, if we remembered that we wanted to divide the value of C by 2 then print this result as well, we could add a couple of extra lines:
10 input A, B
20 Let C = A * B
30 Print C
32 Let D = C/2
35 Print D
40 End
A final point is that we do not say what A, B, C or D stand for before we start. The program implies the necessary information. In other words, we do not have to declare the variables.
- What NAT is used for and basic terms and expressions
- Basics of the iptables command
- Basic Actions
- 1. Basic microprocessor systems
- Basic X Concepts
- Basic Shell Control
- tar: The Most Basic Backup Tool
- A Brief Review of Database Basics
- Understanding SQL Basics
- Using Basic Print Commands
- Basic Sendmail Configuration and Operation
- The Basics of Python