Programming and Graphics

(Kiana) #1

1.5 Computer programming 17


In a typical symbolic language, we issue statements such asA=A+B,which
means “add the number B to the number A.” The CPU executes this task
through a sequence of steps:



  • (FETCH A,R1): copy the binary ofAfrom RAM to the CPU register R1.

  • (FETCH B,R2): copy the binary ofBfrom RAM to the CPU register R2.

  • (ADD, R1,R2,R3): copy the contents of R1 and R2 to the adder, perform
    the addition, and store the results in register R3.

  • (STORE, R3,A): copy the content of R3 to the RAM address ofA.


We see that the mapping of an upper-level language command to machine
language instructions is one-to-many; each command is implemented by several
instructions.


Binary executables


Every computer command or application is implemented in abinary exe-
cutable fileencoding machine-language instructions. This file is loaded into the
RAM by issuing the name of the command or typing the name of the applica-
tion, and then hitting theEnterkey; on a graphical interface, we click on an
icon. To locate a specified binary executable file, the operating system searches
through a user-defined ordered executiondirectory path.


The instruction cycle, also called the fetch-decode-execute cycle (FDX),
describes the time required for a single instruction written in machine language
to be fetched from the RAM, decoded, and executed by the CPU.


Compiling and creating an executable


To write a set of instructions in a mid- or high-level language, we first
generate one file or a number of files containing the main program, subroutines,
and necessary data. The files are created using a text editor, such as the
legendaryvieditor that comes with any Unix distribution, and is also available
in Windows. These files constitute thesource code.


Secondly, we compile the program and subroutines using the language
compiler to create each file’sobject code. The object code is the translation of
the source code into machine language that can be communicated to the CPU.
The compiler basically assigns memory addresses to variables and translates
arithmetic and logical operations into the machine-language instructions. The
compiler itself is a binary executable installed in a directory that must be inc-
luded in the user’s executable directory path. The main difference between

Free download pdf