0% found this document useful (0 votes)
63 views41 pages

Coa 4

This document provides an overview of programming concepts for a basic computer, including: - Machine language and assembly language, how programs are represented internally in binary and how an assembler translates symbolic assembly code. - Common programming structures like loops, arithmetic and logic operations using instructions, and subroutines to reuse code. - How input/output works by assigning character codes and using INP/OUT instructions to transfer data to and from devices.

Uploaded by

aryanshah61203
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views41 pages

Coa 4

This document provides an overview of programming concepts for a basic computer, including: - Machine language and assembly language, how programs are represented internally in binary and how an assembler translates symbolic assembly code. - Common programming structures like loops, arithmetic and logic operations using instructions, and subroutines to reuse code. - How input/output works by assigning character codes and using INP/OUT instructions to transfer data to and from devices.

Uploaded by

aryanshah61203
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

Chapter-3

Programming the Basic Computer

• Introduction,
• Machine Language,
• Assembly Language and Assembler,
• Program loops,
• Programming Arithmetic and
• logic operations,
• Subroutines,
• I-O Programming.
Introduction
• A total computer system includes both hardware
and software . hardware consists of the physical
components and all associated equipment.
• Software refers to the programs that are written
foe the computer.
• It is possible to be familiar with various aspects of
computer software without being concerned with
details of how the computer hardware operates.
• It is also possible to design parts of the hardware
without a knowledge of its software capabilities.
Machine Language
• A program is a list of instructions or statements
for directing the computer to perform a required
data-processing task.

• There are various types of programming


languages that one may write for a computer, but
the computer can execute programs only when
they are represented internally in binary form.
1. Binary code. This is a sequence of
instructions and operands in binary that list
the exact representation of instructions as
they appear in computer memory.
2. Octal or hexadecimal code. This is an
equivalent translation of the binary code to
octal or hexadecimal representation.
3. Symbolic code. The user employs symbols
(letters, numerals, or special characters) for the
operation part, the address part, and other
parts of the instruction code.
Each symbolic instruction can be translated into
one binary coded instruction. This translation is
done by a special program called an assembler.
Because an assembler translates the sym bois,
this type of symbolic program is referred to as
an assembly language program.
• 4. High-level programming languages . These
are special languages developed to reflect the
procedures used in the solution of a problem
rather than be concerned with the computer
hardware behavior. An example of a high-level
programming language is Fortran.
Assembly Language
• A programming language is defined by a set of
rules.
• Users must conform with all format rules of the
language if they want their programs to be
translated correctly.
• Almost every commercial computer has its own
particular assembly language.
• The rules for writing assembly language programs
are documented and published in manuals which
are usually available from the computer
manufacturer.
Rules of the Language
1. The label field may be empty or it may specify a
symbolic address.
2. The instruction field specifies a machine
instruction or a pseudo instruction.
3. The comment field may be empty or it may
include a comment.
• A symbolic address consists of one, two, or three,
but not more than three alphanumeric characters.
The first character must be a letter; the next two
may be letters or numerals. The symbol can be
chosen arbitrarily by the programmer.
• The instruction field in an assembly language
program may specify one of the following items:
1. A memory-reference instruction (MRI)
2. A register-reference or input-output instruction
(non-MRI)
3. A pseudo instruction with or without an operand
• The following is an illustration of the symbols
that may be placed in the instruction field of a
program.

• CLA non-MRI
• ADDOPR d i re c t a d d r e s s M R I
• ADDPTRI i n d i re c t a d d r e s s M R I
Pseudo instruction
• A pseudo instruction is not a machine
instruction but rather an instruction to the
assembler giving information about some
phase of the translation.
The Assembler
• An assembler is a program that accepts a
symbolic language program and produces its
binary machine language equivalent.
• The input symbolic program is called the
source program and the resulting binary
program is called the object program.
• The assembler is a program that operates on
character strings and produces an equivalent
binary interpretation.
Representation of Symbolic Program in
Memory
• Prior to starting the assembly process, the
symbolic program must be stored in memory. The
user types the symbolic program on a terminal.
• A loader program is used to input the characters
of the symbolic program into memory.
• Since the program consists of symbols, its
representation in memory must use an
alphanumeric character code.
• In the basic computer, each character is
represented by an 8-bit code. The high-order
bit is always 0 and the other seven bits are as
specified by ASCII.
• Each character is assigned two hexadecimal
digits which can be easily converted to their
equivalent 8-bit code.
line of code
• A line of code is stored in consecutive memory locations with
two characters in each location. Two characters can be stored in
each word since a memory word has a capacity of 16 bits. A
label symbol is terminated with a comma.
Example : PL3, LDA SUB I
First Pass
• A two-pass assembler scans the entire symbolic
program twice.
• During the first pass, it generates a table that
correlates all user-defined address symbols with
their binary equivalent value.
• The binary translation is done during the second
pass.
• To keep track of the location of instructions, the
assembler uses a memory location counter (LC)
word called a location counter (abbreviated LC).
Second Pass
• Machine instructions are translated during the
second pass by means of tablelookup
procedures.
• A table-lookup procedure is a search of table
entries to determine whether a specific item
matches one of the items stored in the table.
• The assembler uses four tables. Any symbol
that is encountered in the program must be
available as an entry in one of these tables;
otherwise, the symbol cannot be interpreted.
• Four Tables:
• 1. Pseudoinstruction table.
• 2. MRI table.
• 3. Non-MRI table.
• 4. Address symbol table.

• The entries of the pseudoinstruction table are


the four symbols ORG, END, DEC, and HEX.
Each entry refers the assembler to a subroutine
that processes the pseudoinstruction when
encountered in the program.
• One important task of an assembler is to
check for possible errors in the symbolic
program. This is called error diagnostics.

• One such error may be an invalid machine


code symbol which is detected by its being
absent in the MRl and non-MRI tables.
Program Loops
• A program loop is a sequence of instructions that
are executed many times, each time with a
different set of data. Program loops are specified
in Fortran by a DO statement.
• The following is an example of a Fortran program
that forms the sum of 100 integer numbers.

• Statement number 3 is executed 100 times, each time with a


different operand A(J) for J = 1, 2, . . . , 100
Programming Arithmetic
and Logic Operations
• The number of instructions available in a computer
may be a few hundred in a large system or a few dozen
in a small one.
• Some computers perform a given operation with one
machine instruction; others may require a large
number of machine instructions to perform the same
operation.
• As an illustration, consider the four basic arithmetic
operations.
• Some computers have machine instructions to add,
subtract, multiply, and divide.
Multiplication Program
• We now develop a program for multiplying two
numbers.
• To simplify the program, we neglect the sign bit and
assume positive numbers.
• We also assume that the two binary numbers have
no more than eight significant bits so their product
cannot exceed the word capacity of 16 bits.
• It is possible to modify the program to take care of
the signs or use 16-bit numbers.
• However, the product may be up to 31 bits in length
and will occupy two words of memory.
Double-Precision Addition
Logic Operations
• The basic computer has three machine
instructions that perform logic operations:
• AND, CMA, and CLA. The LDA instruction may
be considered as a logic operation that
transfers a logic operand into the AC.
Shift Operations
• The circular-shift operations are machine
instructions in the basic computer.
• The other shifts of interest are the logical shifts
and arithmetic shifts.
• These two shifts can be programmed with a
small number of instructions.
• Shift-right operation : CLE, CIR
• Shift-left operation : CLE, CIL
Subroutines
• Frequently, the same piece of code must be
written over again in many different parts of a
program.
• Instead of repeating the code every time it is
needed, there is an obvious advantage if the
common instructions are written only once.
• A set of common instructions that can be used in
a program many times is called a subroutine.
• A subroutine consists of a self-contained
sequence of instructions that carries out a
given task.
• In the basic computer, the link between the
main program and a subroutine is the BSA
instruction (branch and save return address).
Input-Output Programming
• Users of the computer write programs with symbols
that are defined by the programming language
employed.
• The symbols are strings of characters and each
character is assigned an 8-bit code so that it can be
stored in computer memory.
• A binary-coded character enters the computer when
an INP (input) instruction is executed.
• A binary-coded character is transferred to the output
device when an OUT (output) instruction is executed.
• The output device detects the binary code and types
the corresponding character.
Program Interrupt
• The running time of input and output
programs is made up primarily of the time
spent by the computer in waiting for the
external device to set its flag.

You might also like