UNIT-II-Programming The Basic Computers
UNIT-II-Programming The Basic Computers
CHAPTER SEVEN
2. Software, which refers to the programs that are written for the
computer.
The system software of a computer is divided into two main parts, the
operating system that consists of the programs included in a system
software package and the application programs, in which those
programs are written by the user for solving particular problems.
Page 1 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
In spite of that, the computer executes only the programs that are written
in binary form, there are variety types of programming languages that a
programmer can write his program. In these cases there must be a
translator to translate these programs to the binary form before the
computer can execute them.
Page 2 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
Table 7.1
Binary program
location Instruction Code
0000 0000 0000 0010 0000 0000 0100
0000 0000 0001 0001 0000 0000 0101
0000 0000 0010 0011 0000 0000 0110
0000 0000 0011 0111 0000 0000 0001
0000 0000 0100 0000 0000 0001 0011
0000 0000 0101 1111 1111 1111 1110
0000 0000 0110 0000 0000 0000 0000
2. Table 7.2 shows a hexadecimal program for adding the two numbers.
The hexadecimal representation of the program is more convenient to
use than the binary form for the programmer; however, one must
convert each hexadecimal digit to its equivalent 4-bit number when
the program is entered into the computer.
Table 7.2
Hexadecimal Program
location Instruction
000 2004
001 1005
002 3006
003 7001
004 0013
005 FFFE
006 0000
Page 3 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
3. Table 7.3 shows a program with symbolic operation codes for adding
the two numbers instead of their binary or hexadecimal equivalent.
Here the address parts of memory-reference instructions, as well as
operands, remain in their hexadecimal value. A column of comments
is included for explaining the function of each instruction. Symbolic
programs are easier and preferable to handle. These symbols can be
converted to their binary code equivalent to produce the binary
program.
Table 7.3
Page 4 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
Table 7.4
Table 7.5
Fortran Program
INTEGER A, B, C
DATA A, 13 B, -2
C=A+B
END
The rules of an assembly language for the basic computer are the
following: -
Page 5 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
Example
Page 6 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
Table 7.6
Homework
Translate the following assembly language program to subtract two
numbers to its equivalent binary from.
Page 7 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
Operations that are executed with one machine instruction are said to be
implemented by hardware, while those operations that are executed by
a program are said to be implemented by software.
Page 8 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
1. Multiplication Operation
To simplify the process, assume unsigned positive binary numbers
and each number have no more than 8-bits so the result of
multiplication does not exceeds the word capacity of 16-bits.
Multiplicand X = 00000111
Multiplier Y = 00001010
00000000
00001110
00000000
00111000
01000110
Note. The computer can use numbers with eight significant bits to
produce a product of up to 16 bits.
Page 9 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
CTR ← -8
P←0
E←0
AC ← Y
cir EAC
Y ← AC
0= =1
E
P←P+X
E←0
AC ← X
cil EAC
X ← AC
CTR ← CTR + 1
0≠ =0 Sto
CTR
Figure 7.1
Page 10 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
ORG 200
LOP, CLE /Clear E
LDA Y /Load multiplier
CIR /Shift multiplier bit to E
STA Y /Store shifted multiplier
SZE /Check if the shifted bit in E is zero
BUN ONE /If the bit is one; go to ONE
BUN ZRO /If the bit is zero; go to ZRO
ONE, LDA X /Load multiplicand
ADD P /Add to partial product
STA P /Store partial product
CLE /Clear E
ZRO, LDA X /Load multiplicand
CIL /Shift left
STA X /Store shifted multiplicand
ISZ CTR /Increment counter
BUN LOP /For counter not zero; repeat loop
HLT /If counter is zero; Halt
CTR, DEC -8 /This location serves as a counter
X, HEX 0007 /Location of multiplicand
Y, HEX 000A /Location of multiplier
P, HEX 0 /Location of the product
END
Note
The above program to be a general program for multiplying any two
unsigned numbers; the initialization of the multiplicand and multiplier
into locations X & Y respectively must be included. The initialization
process also must include the initialization of the counter CTR to -8
and P to zero.
Page 11 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
2. Double-Precision Addition
A double precision number is a number that stored in two memory
words of the memory.
The program for adding two numbers is listed below. First the two low-
order portions are added and the carry transferred into E, the content
of AC stored into the memory location CL (the 16 least significant bits
of the sum). AC is cleared and the bit in E is circulated into the least
significant bit of the accumulator AC (0). The two high-order portions
are then added to the carry and the content of AC stored into the
memory location CH (the 16 most significant bits of the sum).
Page 12 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
3. Logic Operations
In chapter six it is shown that the basic computer has three machine
instructions that perform logic operations: AND, CMA, and CLA. Also
LDA instruction can be considered as logic operation that transfers a
logic operand into the AC. Any logic function can be implemented
using the AND and complement operation CMA.
Example
Write a program to forms the OR logic operation of two logic 16-bit
operands A & B given that A ∨ B = ( A ⋅ B ) .
The Program
LDA A /load the first operand A into AC
CMA /Complement to get A complement ( A )
STA TEM /Store in temporary location TEM
LDA B /load the second operand B into AC
CMA /Complement to get B complement (B )
AND /AND with the content of TEM ( A ∧ B )
TEM /Complement the result to obtain A
A, CMA
B, xxxx (AB ) = A ∨ B
xxxx /Location of the first operand
/Location of the second operand
4. Shift Operations
The basic computer as it was shown before contains only the circular-
shift instructions (CIR & CIL) which executes the circular-shift
operations.
The logical and arithmetic shift operations can be programmed with a
number of the computer instructions as follows:
Page 13 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
Examples
(1) The logical shift-right operation can be implemented by the
following two instructions:
CLE
CIR
CLE
CIL
CLE /Clear E to 0
SPA /Skip if AC is positive; E remains 0
CME /AC is negative; set E to 1
CIR /Circulate E & AC
Page 14 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
CLE /Clear E to 0
CIL /Circulate E & AC
7.5. Subroutines
A Subroutine can be defined as a set of instructions that can be used in
a program many times.
2. A branch can be made to the subroutine from any part of the main
program.
For basic computer the instruction BSA (Branch and Save return
Address) is the link instruction between the main program and the
subroutine.
Page 15 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
Page 16 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
The program starts with the instruction SKI which checks the input flag
to see if a character is available to transfer.
If the input flag is 1, the next instruction BUN is skipped. The INP
instruction transfers the binary-coded character into AC (0-7). By the
OUT instruction, the character is printed by the output device.
If the input flag is 0, the next instruction BUN is executed and a branch
to return and check the input flag again.
Page 17 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
The two instructions SKI & BUN will be executed many times before a
character is transferred into the accumulator, because the input device is
much slower than the computer.
The following set of instructions, print a character initially stored in
memory.
The program starts with the instruction LDA to load the binary-coded
character into the AC from the memory location CHR. The instruction
SKO checks the output flag, if its 1, the character is transferred from AC
to the printer. If the output flag is 0, the computer remains in a two
instruction loop (SKO & BUN) checking the flag bit.
Character Manipulation
To pack two characters in one memory word for the purpose of character
manipulation, the subroutine named IN2 that inputs two characters and
packs them into the AC is shown below.
It is clear that this subroutine calls twice the subroutine SH4 to shift the
accumulator left eight times.
Page 18 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
Program Interrupt
The interrupt facility is useful when two or more programs reside in the
memory at the same time.
Even though two or more programs may reside in the computer memory,
only one program can be executed at a given time and this program is
referred to as the running program. The other programs are usually
waiting for input or output data.
The function of the interrupt facility is to take care of the data transfer of
one (or more) program while another program is currently being
executed. The running program must include an ION instruction to turn
the interrupt on. If the interrupt facility is not used, the program must
include an IOF instruction to turn it off.
The interrupt facility allows the running program to proceed until the input
or output device sets its ready flag.
Whenever a flag is set to 1, the computer completes the execution of the
instruction in progress and then acknowledges the interrupt. The result
of this action is that the return address is stored in location 0. The
instruction in location 1 is then performed; this initiates a service routine
for the input or output transfer.
The service routine can be stored anywhere in memory provided a
branch to the start of the routine is stored in location 1.
The service routine must have instructions to perform the following tasks:
-
Page 19 of Chapter 7
Computer Architecture
Chapter Seven Programming the Basic Computer
Table 7.8
A typical computer may have many more input and output devices
connected to the interrupt facility.
Page 20 of Chapter 7