Está en la página 1de 7

1.

1 Introduction
A computer is a set of electronic devices which when combined are capable of performing
computations and making logical decisions at speeds millions and even billions of times faster
than humans can. The various devices are collectively called hardware. (e.g. keyboard, monitor,
hard disk etc.)

Computers process data under the control of sets of instructions called computer programs.

The programs that run on a computer are called software. Computer programmers do a very
important job. They create software that transforms computers into the specialized tools of many
trades. Without programmers, the users of computers would have no software, and without
software, computers would not be able to do anything.

Computer programming is both an art and a science. It is an art because every aspect of a
program should be carefully organized and designed. Listed below are a few of the things that
must be considered when creating any real-world program:

• Logical flow of the instructions


• Mathematical calculations
• The appearance
• The way information is presented to the user
• The program’s “user-friendliness”
• Manuals and other forms of written documentations

There is also a scientific or engineering side to programming because programs rarely work right
the first time they are written. Hence a lot of experimentation, correction and redesigning is
required.

In this course, I'm going to teach you how computer programs work by teaching you how to
program using MATLAB programming language.

In order to teach you about computer programming, I am going to make the following
assumptions:

• I am going to assume that you know nothing about computer programming now. If you
already know something then the first part of this course will seem elementary to you.
• I am going to assume you do know something about the computer you are using. That is,
I am going to assume you already know how to edit a file, copy and delete files, rename
files, find information on your system, etc.
• For simplicity, I am going to assume that you are using a machine running a Windows
OS. It should be relatively straightforward for people running other operating systems to
map the concepts over to those.

1.2 A Little Terminology


Keep in mind that I am assuming that you know nothing about programming. Here are two
vocabulary terms that will make things understandable:

Computer program - A computer program is a set of instructions that tell a computer exactly
what to do. The instructions might tell the computer to add up a set of numbers, or compare two
numbers and make a decision based on the result, or whatever. But a computer program is simply
a set of instructions for the computer, like a recipe is a set of instructions for a cook or musical
notes are a set of instructions for a musician. The computer follows your instructions exactly and
in the process does something useful -- like balancing a checkbook or displaying a game on the
screen.

Programming language - In order for a computer to recognize the instructions you give it, those
instructions must be written in a form the computer can process -- a programming language is
used to give the instructions which then must be compiled into the appropriate form. There are
many computer programming languages -- Fortran, Cobol, Basic, Pascal, C++, Java, MATLAB -
- just like there are many spoken languages. They all express approximately the same concepts in
different ways.

1.3 Basic Computer Components


Regardless of differences in physical appearance, virtually every computer may be represented
by the following units or devices.

• Input unit – Information is entered into the computer via this unit. The devices used to
input the data are called input devices. Many devices can provide input:
o Keyboard, mouse, scanner, digital camera, microphone
o Disk drives and CD-ROM
• Output unit – Processed information is received via this unit from various output
devices. Many devices can be used for output:
o Computer monitor and printer
o Floppy, zip disk drives
o Writable CD drives
• Memory unit – Stores information that has been entered through the input unit so that
the information may be made available for processing when needed. The memory unit
also retains processed information until the information can be outputted by the output
unit. Main memory is erased when program terminates or computer is turned off, that is,
it is volatile.
o Also called Random Access Memory (RAM)
o Organized as follows:
 bit: smallest piece of memory. Has values 0 (off, false) or 1 (on, true)
 byte: 8 consecutive bits. Bytes have addresses.
 Each byte in memory is identified by a unique number known as an
address.

In the figure above, the number 149 is stored in the byte with the address 16, and the number 72
is stored at address 23.

• Central Processing Unit (CPU) – The part of the computer that executes the instructions
(program) stored in memory. This unit does almost all processing and coordination of
activities. It collects information from the memory unit, processes the information and
then sends the information back to the memory unit. The CPU is made up of the Control
Unit and the Arithmetic/Logical Unit.
o Control Unit - The component of the CPU that controls the actions of the other
components so that instructions are executed in the correct sequence.
 Retrieves and decodes program instructions
 Coordinates activities of all other parts of computer
o Arithmetic/Logical Unit (ALU) - the component of the CPU that performs
arithmetic and logical operations.
 Hardware optimized for high-speed numeric calculation
 Hardware designed for true/false, yes/no decisions

• Secondary Storage Unit – This is the unit that provides long-term, high-capacity
storage. It is important to note that the Memory Unit is relatively low-capacity and short-
term (volatile).

1.4 Everything is a number


At the heart of a digital computer is the central processing unit (CPU) which performs the
logical and arithmetical operations on streams of numbers as controlled by a “program” which is
itself a stream of numbers. The CPU has privileged access to the computer memory which can
be thought of as a large number of boxes in which numbers can be stored and later
retrieved. The CPU can also send and receive numbers to and from a set of input-output
ports. These act as gateways from the CPU to other devices, such as keyboards, displays,
printers, disks, analogue I/O devices, or network connections to other computers. Collectively
these external devices are called peripherals. The CPU can select a peripheral and control its
operation by sending appropriate number streams to the port to which it is connected.

The CPU can only manipulate numbers, so all pieces of information that we want the computer
to manipulate must be stored as numbers. Such information includes: numerical values,
keyboard or display characters, arithmetic operations, the addresses of memory locations, the
addresses of ports, and even the possible set of instructions that the CPU can perform. All these
must be stored as numbers.

For example, each character on your keyboard is represented by a unique binary code. The
character encoding scheme was developed by the American Standards Association (ASA) and
named the ‘American Standard Code for Information Interchange (ASCII)’ – see table below.

ASCII Table
The philosophy of numbers for anything and everything is the basis of the power of the
computer. When the CPU does a calculation and generates a numerical answer, that number
need not be just the size of something, but it can be a character, a memory address or even the
next operation of the CPU.

1.5 Software hierarchy

Programmers write instructions in various programming languages, some directly understandable by


computers and others requiring intermediate translation steps. Hundreds of computer languages are in
use today. These may be divided into three general types:
1. Machine languages

2. Assembly languages

3. High-level languages

Any computer can directly understand only its own machine language. Machine language is the "natural
language" of a computer and as such is defined by its hardware design. [Note: Machine language is
often referred to as object code. This term predates "object-oriented programming." These two uses of
"object" are unrelated.] Machine languages generally consist of strings of numbers (ultimately reduced
to 1s and 0s) that instruct computers to perform their most elementary operations one at a time.
Machine languages are machine dependent (i.e., a particular machine language can be used on only one
type of computer). Such languages are cumbersome for humans, as illustrated by the following section
of an early machine-language program that adds overtime pay to base pay and stores the result in gross
pay:

+1300042774

+1400593419

+1200274027

Machine-language programming was simply too slow, tedious and error-prone for most programmers.
Instead of using the strings of numbers that computers could directly understand, programmers began
using English-like abbreviations to represent elementary operations. These abbreviations formed the
basis of assembly languages. Translator programs called assemblers were developed to convert early
assembly-language programs to machine language at computer speeds. The following section of an
assembly-language program also adds overtime pay to base pay and stores the result in gross pay:

load basepay

add overpay

store grosspay
• Source Program - A program written in a human readable form.

• Object Program - The machine language version of a source program.

Although the source code is clearer to humans, it is incomprehensible to computers until translated to
machine language.

Computer usage increased rapidly with the advent of assembly languages, but programmers still had to
use many instructions to accomplish even the simplest tasks. To speed the programming process, high-
level languages were developed in which single statements could be written to accomplish substantial
tasks. Translator programs called compilers convert high-level language programs into machine
language. High-level languages allow programmers to write instructions that look almost like everyday
English and contain commonly used mathematical notations. A payroll program written in a high-level
language might contain a statement such as

grossPay = basePay + overPay;

Machine Language Assembler Language High-Level Language

+1300042774 LOAD basepay ADD


+1400593419 overpay STORE grosspay = basepay + overpay;
+1200274027 grosspay

MATLAB is a high-level language based on algebraic notation.

También podría gustarte