Студопедия

КАТЕГОРИИ:


Архитектура-(3434)Астрономия-(809)Биология-(7483)Биотехнологии-(1457)Военное дело-(14632)Высокие технологии-(1363)География-(913)Геология-(1438)Государство-(451)Демография-(1065)Дом-(47672)Журналистика и СМИ-(912)Изобретательство-(14524)Иностранные языки-(4268)Информатика-(17799)Искусство-(1338)История-(13644)Компьютеры-(11121)Косметика-(55)Кулинария-(373)Культура-(8427)Лингвистика-(374)Литература-(1642)Маркетинг-(23702)Математика-(16968)Машиностроение-(1700)Медицина-(12668)Менеджмент-(24684)Механика-(15423)Науковедение-(506)Образование-(11852)Охрана труда-(3308)Педагогика-(5571)Полиграфия-(1312)Политика-(7869)Право-(5454)Приборостроение-(1369)Программирование-(2801)Производство-(97182)Промышленность-(8706)Психология-(18388)Религия-(3217)Связь-(10668)Сельское хозяйство-(299)Социология-(6455)Спорт-(42831)Строительство-(4793)Торговля-(5050)Транспорт-(2929)Туризм-(1568)Физика-(3942)Философия-(17015)Финансы-(26596)Химия-(22929)Экология-(12095)Экономика-(9961)Электроника-(8441)Электротехника-(4623)Энергетика-(12629)Юриспруденция-(1492)Ядерная техника-(1748)

Programming: Languages




Many computer languages are available for writing computer programs. They each have advantages for certain kinds of tasks.

Let's check out some examples of the various types of computer languages and see what they are used for.

Machine Language = The native tongue of the CPU. Each design for a CPU has its own machine language. This is the set of instructions that the chip uses itself. So it is made up of sets of 0's and1's, that is binary numbers. Very hard for people to work with.  
10 23 11 FF 12 12 13 10 14 50 15 23 16 30 17 40 18 C0 19 00   Machine language looks like it's just numbers. In the program segment at left the first column tells the computer where to fill memory and the hexadecimal (base 16) numbers in the second column are the values to put into memory at those locations. For more information on hexadecimal numbers, see Base Arithmetic.

Here's another example of machine language.

The segment of Java code:

int counter = 0;

counter = counter + 1;

might be translated into machine language as:

 
Assembly Language = Codes or abbreviations for the machine language instructions In an assembly language each machine language instruction is assigned a code. So instead of having to remember a string of 0's and 1's, the programmer would only need to remember short codes like ADD, MOV, or JLE. Certainly an improvement over 000101000100010001000100001000101010111110!! But not really "user friendly" either. The assembly language program below reads two characters and prints them on the screen. The text to the right of the semicolons (;) is ignored by the computer. It's there to explain the program to anyone looking at the code. Notice that each little step must be coded. All this just to display 2 characters!
;name of the program:one.asm ; .model small .stack .code mov AH,1h;Selects the 1 D.O.S. function Int 21h;reads character and return ASCII ; code to register AL mov DL,AL;moves the ASCII code to register DL sub DL,30h;makes the operation minus 30h to ; convert 0-9 digit number cmp DL,9h;compares if digit number it was ; between 0-9 jle digit1;If it true gets the first number ; digit (4 bits long) sub DL,7h;If it false, makes operation minus ; 7h to convert letter A-F digit1: mov CL,4h;prepares to multiply by 16 shl DL,CL;multiply to convert into four bits upper int 21h;gets the next character sub AL,30h;repeats the conversion operation cmp AL,9h;compares the value 9h with the content ; of register AL jle digit2;If true, gets the second digit number sub AL,7h;If no, makes the minus operation 7h ; digit2: add DL,AL;adds the second number digit mov AH,4CH Int 21h;21h interruption End;finish the program code
FORTRAN = Formula Translation FORTRAN was created around 1957 to help scientists, engineers, and mathematicians write programs that describe complex situations, like nuclear power plant monitoring, nuclear explosions, and space flight. This is still a widely used language. It was the first successful high-level program. Newer versions have been released. The most recent standard version is Fortran 2008 which was finalized Sept. 2010. (Originally FORTRAN in all caps was required but recent version names can use normal case.) The example Fortran program below accepts the bus number 99 and displays the command "TAKE BUS 99"
PROGRAM IDEXMP INTEGER BUS_NUM BUS_NUM = 99 WRITE(*,*) ' TAKE BUS ', BUS_NUM END  
COBOL = Common Business Oriented Language COBOL was written about 1960 with business applications in mind. It has a very English-like structure, using sentences and paragraphs, though they are certainly different from those in a novel. This helps business people who are not high-powered programmers to be able to write or edit a program. But it has the disadvantage of tending toward wordy, lengthy programs. It is a good language for direct, simple programs. COBOL was used to create many programs for the main frames of large companies. These programs were upgraded during the Y2K fixes for the year 2000. So it seems likely that COBOL programs will be around for a long time yet. [See the article at http://www.infogoal.com/cbd/cbdz009.htm for a longer discussion of this issue.] The example below accepts two numbers, multiplies them, and displays the numbers and the result. Look at the PROCEDURE DIVISION to see where the calculation is done.
  $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. FragmentA. AUTHOR. Michael Coughlan.     DATA DIVISION.   WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS.   PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. MULTIPLY Num1 BY Num2 GIVING Result. ACCEPT Num2. DISPLAY "Result is = ", Result. STOP RUN.
BASIC = Beginner's All Symbolic Instruction Code This language was written in 1964 (truly the age of dinosaurs for computers!) for college students to use to learn programming concepts. Originally BASIC was intended only for classroom use. But the language has proven to be highly useful in the real world. A wide variety of "dialects" of BASIC developed through the years. Visual Basic is now very popular for programming Windows applications. Microsoft Visual Basic for Applicationsis an example of a subset of BASIC that is modified to help users write small subprograms called scripts or macros for use with applications like MS Word. Some applications used to have their own variety of BASIC for writing their macros, like Word Basic and Excel Basic. The creators of BASIC wanted a language that felt more like regular English. So while it doesn't LOOK much like English, it uses enough of the syntax of English to give it a more natural feel than many other computer languages. The short program below is written in BASIC. It accepts a distance in miles, yards, feet, and inches and converts it to kilometers, meters, and centimeters. Notice how the programmer can write equations to do the calculations.
' English to Metric Conversion ' J. S. Quasney ' **************************** PRINT: PRINT "English to Metric Conversion" PRINT INPUT "Miles: ", Miles INPUT "Yards: ", Yards INPUT "Feet: ", Feet INPUT "Inches: ", Inches Inches = 63360 * Miles + 36 * Yards + 12 * Feet + Inches Meters# = Inches / 39.37# Kilometers = INT(Meters# / 1000) Meters# = Meters# - 1000 * Kilometers Final.Meters = INT(Meters#) Centimeters = Meters# - Final.Meters Centimeters = 100 * Centimeters Centimeters = INT((Centimeters +.005) * 100) / 100 PRINT PRINT "Kilometers:"; Kilometers PRINT "Meters:"; Final.Meters PRINT "Centimeters:"; Centimeters END
C Originally created for writing system software, C has evolved into C++. Both are widely used by programming professionals for all sorts of programs. The program below is written inC++. It accepts 3 numbers and checks to see if the third is equal to the difference of the first two.
#include <iostream.h> void main() { int a, b, c; cout << "Please enter three numbers\n"; cout << "a: "; cin >> a; cout << "\nb: "; cin >> b; cout "\nc: "; cin >> c;   if (c=(a-b)) { cout << "a: "; cout << a; cout << " minus b: "; cout << b; cout << " equals c: "; cout << c << endl; } else cout << "a-b does not equal c:" << endl; }
Java The language Java is used to write both full computer applications and small applets for web pages. Its goal is to create applications that will run on any computer, unlike other languages which are not cross-platform. (By the way, don't confuse Java with JavaScript, a scripting language commonly used on web pages. The only thing they share is the letters in their names! JavaScript started life as LiveScript in about 1994. Netscape bought it and renamed it, apparently for marketing reasons.) The example below draws a box on an HTML page and counts the number of times you have clicked inside the box.
import java.applet.*; import java.awt.*; public class exfour extends Applet { int i; public void init() { resize(300,300); } public void paint(Graphics g) { g.drawString("You clicked the mouse "+i+" Times",50,50); } public boolean mouseUp(Event e, int x, int y) { i++; repaint(); return true; } }



Поделиться с друзьями:


Дата добавления: 2014-12-23; Просмотров: 426; Нарушение авторских прав?; Мы поможем в написании вашей работы!


Нам важно ваше мнение! Был ли полезен опубликованный материал? Да | Нет



studopedia.su - Студопедия (2013 - 2024) год. Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав! Последнее добавление




Генерация страницы за: 0.009 сек.