Skip to content
The Computer Science
TheCScience
  • Engineering Subjects
    • Human Values
    • Computer System Architecture
    • Digital Communication
    • Internet of Things
  • NCERT Solutions
    • Class 12
    • Class 11
  • HackerRank solutions
    • HackerRank Algorithms Problems Solutions
    • HackerRank C solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
The Computer Science
TheCScience

Programming Arithmetic And Logic Operations in Computer Architecture

YASH PAL, February 28, 2026February 28, 2026

Programming Arithmetic and Logic Operations in Computer Architecture – Some of the computers perform a given operation with one machine instruction, while others may require a large number of machine instructions to perform the same operation. Lets a consider the four basic arithmetic operations and understand how a computer executes these arithmetic operations.

Some computers have machine instructions to add, subtract, multiply, and divide. Others, such as the basic computer, have only one arithmetic instruction, such as ADD. Operations not included in the set of machine instructions must be implemented by a program. Operations that are implemented in a computer with one machine instruction are said to be implemented by hardware. Operations implemented by a set of instructions that constitute a program are said to be implemented by software.

Some computers provide an extensive set of hardware instructions designed to speed up common tasks. Others contain a smaller set of hardware instructions and depend more heavily on the software implementation of many operations.

Hardware implementation is more costly because of the additional circuits needed to implement the operation. Software implementation results in long programs both in the number of instructions and in execution time.

Multiplication Program

We will develop a program to multiply two numbers. We assume a positive number and neglect the sign bit for simplicity. And 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.

The multiplication process consists of checking the bits of the multiplier Y and adding the multiplicand X as many times as there are 1’s in Y, provided that the value of X is shifted left from one line to the next. Since the computer can add only two numbers at a time, we reserve a memory location, denoted by P, to store intermediate sums.

The intermediate sums are called partial products since they hold a partial product until all numbers are added. As shown in the numerical example under P, the partial product starts with zero. The multiplicand X is added to the content of P for each bit of the multiplier Y that is 1.

The value of X is shifted left after checking each bit of the multiplier. The final value in P forms the products. The numerical example has numbers with four significant bits. When multiplied, the product contains eight significant bits. The computer can use numbers with eight significant bits to produce a product of up to 16 bits.

Flowchart for multiplication program
Flowchart for multiplication program

X: holds the multiplicand
Y: holds the multiplier
P: holds the product

Example with four significant digits

X = 0000 1111
Y = 0000 1011
   __________
    0000 1111
    0001 1110
    0000 0000
    0111 1000
   __________
    1010 0101

     P
____________
0000 0000
0000 1111
0010 1101
0010 1101
1010 0101

The program in the table below lists the instructions for multiplying two unsigned numbers. The initialization is not listed but should be included when the program is loaded into the computer. The initialization consists of bringing the multiplicand and multiplier into locations X and Y, respectively; initializing the counter to -8; and initializing location P to zero.

If these locations are not initialized, the program may run with incorrect data. The program itself is straightforward and follows the steps listed in the flowchart. The comments may help in following the step-by-step procedure.

ORG 100
LOP,CLE
LDA Y
CIR
STA Y
SZE
BUN ONE
BUN ZRO
/Clear E
/Load multiplier
/Transfer multiplier bit to E
/Store shifted multiplier
/Check if bit is zero
/Bit is none: go to ONE
/Bit is zero: go to ZRO
ONE,LDA X
ADD P
STA P
CLE
/Load multiplicand
/Add to partial product
/Store partial product
/Clear E
ZRO,LDA X
CIL
STA X
ISZ CTR
BUN LOP
HLT
/Load multiplicand
/Shift left
/Store shifted multiplicand
/Increment counter
/Counter not zero; repeat loop
/Counter is zero; halt
CTR,DEC-8/This location serves as a counter
X,HEX 000F/This location serves as a counter
Y,HEX 00B/Multiplicand stored here
P,HEX 0/Multiplier stored here
END/Product formed here
A program to multiply two positive numbers

Double Precision Addition

When two 16-bit unsigned numbers are multiplied, the result is a 32-bit product that must be stored in two memory words. A number stored in two memory words is said to have double precision. When a partial product is computed, a double-precision number must be added to the shifted multiplicand, which is also a double-precision number.

For greater accuracy, the programmer may wish to employ double-precision numbers and perform arithmetic with operands that occupy two memory words. We now develop a program that adds two double-precision numbers. One of the double-precision numbers is placed in two consecutive memory locations. AL and AH, with AL holding the 16 low-order bits. The other numbers are placed in BL and BH. The program is listed in the table given below.

The two low-order portions are added, and the carry is transferred into E. The AC is cleared, and the bit in E is circulated into the least significant position of the AC. The two high-order portions are then added to the carry, and the double-precision sum is stored in CL and CH.

LAD AL/Load A Low
ADD BL/Add B low, Carry in E
STA CL/Store in C low
CLA/Clear AC
CIL/Circulate to bring carry into AC(16)
ADD AH/Add A high and carry
ADD BH/Add B high
STA CH/Store in C high
HLT
AL,——/Locations of operand
AH,——
BL,——
BH,——
CL,——
CH,——
Program to add two double-precision numbers

Logical Operation

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 AC. We listed 16 different logic operations. All 16 logic operations can be implemented by software means because any logic function can be implemented using the AND and complement operations. For example, the OR operation is not available as a machine instruction in the basic computer. From DeMorgan’s theorem, we recognize the relation x+y=(x’y’)’. The second expression contains only AND and complement operations. A program that forms the OR operation of two logic operands, A and B, is as follows:

LDAALoad first operand A
CMAComplement to get A
STA TMPStore in a temporary location
LDABLoad second operand B
CMAComplement to get B
AND TMPAND with A to get A ∧ B
CMAComplement again to get A v B
OR operation of two logic operands

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. The logical shift requires that zeros be added to the extreme positions. This is easily accomplished by clearing E and circulating the AC and E. Thus, for a logical shift-right operation, we need the two instructions.


CLE
CIR

For a logical shift-left operation, we need the two instructions.

CLE
CIL

The arithmetic shifts depend on the type of representation of negative numbers. For the basic computer, we have adopted the signed-2’s complement representation. The rules for arithmetic shifts are listed in the Shift Micro Operations Article. For an arithmetic right-shift, it is necessary that the sign bit in the leftmost position remain unchanged. But the sign bit itself is shifted into the high-order bit position of the number. The program for the arithmetic right shift requires that we set E to the same value as the sign bit and circulate right, thus:

CLE  /Clear E to 0
SPA  /Skip if AC is positive; E remains 0
CME /AC is negative; set E to 1
CIR /Circulated E and AC
Computer System Architecture engineering subjects Computer System Architecture

Post navigation

Previous post
Next post

Basic structure of a computer
Functional Units of a Computer
Development of Computers
Von Neumann and Harvard Machine Architecture
Flynn Classification
Computer Structure Architecture
Basic Computer Data Types
Arithmetic Complement
Real Numbers Representation
Interfacing Logic Devices
Levels of Design Abstraction
Performance Metrics

Register Transfer Language
Memory Transfer
Arithmetic Micro-operations
Arithmetic Complements
Logic Micro-operations
Shift Micro-operations
Bus Architecture
Data Transfer
Bus and Memory Transfer
Central Processing Unit
CPU Bus Architecture

Difference between Computer Architecture and Organization
Computer Register and Types
Common Bus System
Instruction Format
Instruction Types
Instruction Cycle
Fetch Decode Execute Instruction Cycle
Timing and Control of Instruction Cycle
Input-Output and Interrupt
Memory Reference Instructions
Addressing Modes
Design of a basic computer
Design of Accumulator Unit
Design of Control Unit
Difference between Hardwired Control and Microprogrammed Control

Basic Function of a Computer
Register organization
General Register Organization
Stack organization
Infix to Reverse Polish Notation Conversion
Instruction Types and their classifications
Data transfer and manipulation
Program control
RISC and CISC
Difference between RISC and CISC

Parallel Processing
Pipeline
Types of Pipeline
Arithmetic Pipeline
Instruction Pipeline
Hazards
RISC Pipeline
Vector Processing
Array Processors

Machine Language
Assembly Language
Arithmetic and Logical Operations
Subroutine
Data Representation
Addition and Subtraction
Adder Circuits
Shift and Add Multiplication Method
Booth's Algorithm
Restoring Division Algorithm
Non-Restoring Division Algorithm
Array Multiplier
Hardwired control and Microprogrammed control Difference

Memory Classification
Memory Characteristics
Memory Organization
Memory Types
Auxiliary Memory
Associative Memory
Cache Memory
Virtual Memory
Paging and Segmentation Difference
Multiprocessor
Interconnection Structures
Interprocessor Arbitration
Interprocessor Communication and Synchronization
Cache Coherence
Shared Memory Multiprocessors

Input Output Interface
Asynchronous Data Transfer
Modes of Data Transfer
Input-Output Programming
Priority Interrupt
Microprogramming
Control Memory
Address Sequencing
Micro Program Examples
Direct Memory Access
Input-Output Processor
Serial Communication

TheCScience

We at TheCScience.com are working towards the goal to give free education to every person by publishing in dept article about Secondary, Senior-Secondary, and Graduation level subjects.

Pages

About US

Contact US

Privacy Policy

DMCA

Our Tools

Hosting - get 20% off

Engineering Subjects

Internet of Things

Human Values

Digital Communication

Computer System Architecture

Programming Tutorials

Data Structure and Algorithm

C

Java

NCERT

Class 12th

©2026 TheCScience | WordPress Theme by SuperbThemes