0% found this document useful (0 votes)
3 views33 pages

FOC Mod2 Notes

The document outlines the foundational concepts of computing, focusing on binary representation, number systems, and data encoding methods such as ASCII and Unicode. It explains how data is represented in binary, the significance of different number systems (decimal, binary, octal, hexadecimal), and the processes for converting between these systems. Additionally, it covers memory representation and the importance of binary in computer architecture and data storage.

Uploaded by

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

FOC Mod2 Notes

The document outlines the foundational concepts of computing, focusing on binary representation, number systems, and data encoding methods such as ASCII and Unicode. It explains how data is represented in binary, the significance of different number systems (decimal, binary, octal, hexadecimal), and the processes for converting between these systems. Additionally, it covers memory representation and the importance of binary in computer architecture and data storage.

Uploaded by

sreelakshmis096
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

Foundations Of Computing: From Hardware Essentials To


Web Design GXEST203 2024 scheme
MODULE-2
Binary representation of data and numbers, Integer Representation, Data storage units -
bits, bytes, kilobytes, etc., ASCII and Unicode, CPU Architecture and Instruction Set:
Basic CPU architecture - ALU, registers, control unit, Instruction format and assembly
language (basics only) Fetch- execute cycle and instruction execution.
BINARY REPRESENTATION OF DATA AND NUMBERS
The data stored in the computer may be of different kinds, as follows—
● Numeric data (0, 1, 2, …, 9)
● Alphabetic data (A, B, C, …, Z)
● Alphanumeric data—Combination of any of the symbols— (A, B, C… Z), (0, 1… 9), or
special characters (+, −, Blank), etc.
All kinds of data, be it alphabets, numbers, symbols, sound data or video data, is represented in terms
of 0s and 1s, in the computer. Each symbol is represented as a unique combination of 0s and 1s.
NUMBER SYSTEM
● A number system in base r or radix r uses unique symbols for r digits.
● One or more digits are combined to get a number.
● The base of the number decides the valid digits that are used to make a number.
● In a number, the position of digit starts from the right-hand side of the number
In computers, there are concerned with four kinds of number systems, as follows—
Decimal Number System —Base 10
Binary Number System —Base 2
Octal Number System —Base 8
Hexadecimal Number System—Base 16
Decimal Number System
It consists of 10 digits—0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.
All numbers in this number system are represented as a combination of digits 0—9. For example,
34, 5965 and 867321.
The position value and quantity of a digit at different positions in a number are as follows—

1
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

Binary Number System


The binary number system consists of two digits—0 and 1.
All binary numbers are formed using a combination of 0 and 1. For example, 1001, 11000011 and
10110101.
The position value and quantity of a digit at different positions in a number are as follows—

Octal Number System


The octal number system consists of eight digits—0 to 7.
All octal numbers are represented using these eight digits. For example, 273, 103, 2375, etc.
The position value and quantity of a digit at different positions in a number are as follows—

Hexadecimal Number System


The hexadecimal number system consists of sixteen digits—0 to 9, A, B, C, D, E, F, where (A is
for 10, B is for 11, C-12, D-13, E-14, F-15).
All hexadecimal numbers are represented using these 16 digits. For example, 3FA, 87B, 113, etc.
The position value and quantity of a digit at different positions in a number are as follows—

2
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

Binary Representation of Data and Numbers


What is Binary?
● Binary is a number system with a base of 2.
● It uses only two digits: 0 and 1.
● It is the foundation of all computer operations because computers use transistors that have
two states: ON (1) and OFF (0).

Why Do Computers Use Binary?


1. Simplicity in Hardware Design
● Transistors: The core components of digital circuits operate in two states:
○ ON: High voltage, represented by 1.
○ OFF: Low voltage, represented by 0.
● Designing circuits with two states is much simpler than handling multiple states
(like decimal systems with 10 states).
2. Reliability
● Error Reduction:
○ Binary signals are less prone to distortion compared to analog signals or systems
with multiple states.
○ Example: A signal can either be high (1) or low (0), making it easier to detect and
correct errors.
● Noise Immunity: Binary systems are more resistant to electrical noise because small
fluctuations in voltage won't affect the interpretation of 0 or 1.
3. Cost-Effectiveness and Scalability
● Circuit Design:
○ Digital circuits (e.g., logic gates like AND, OR, NOT) are built using simple
binary operations.
○ Reduces manufacturing complexity and cost.
● Memory and Storage: Binary representation allows efficient use of memory, with each
bit (binary digit) representing a single state.
4. Universality
● Binary is the universal language of computers, enabling standardization across all
digital devices.

Decimal to Binary Conversion


Repeatedly divide the decimal number by 2 and write down the remainders. The remainders, read in
reverse order, form the binary representation.

3
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

1. Steps Divide the decimal number by 2.


2. Write down the remainder, which will be either 0 or 1.
3. Repeat steps 1 and 2 using the quotient from the previous division as the new decimal number.
4. Read the remainders in reverse order to get the binary representation.

Floating Point Number to Binary


Steps for conversion of a decimal fraction to any other base are—
1. Multiply the fractional number with the to Base, to get a resulting number.
2. The resulting number has two parts, non-fractional part and fractional part.
3. Record the non-fractional part of the resulting number.
4. Repeat the above steps at least four times.
5. Write the digits in the non-fractional part starting from upwards to downwards.
EXAMPLE : Convert 0.2345 from Base 10 to Base 2

4
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

Example : Convert 34.4674 from Base 10 to Base 2.

Binary to Decimal Conversion

5
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

A binary number is converted to decimal equivalent simply by summing together the weights of
various positions in the binary number

Example: 00001001

To compute a number in this system, you would multiply the digit value by the place
value, then add them all together: (1*8)+(0*4)+(0*2)+(1*1) = 9

Binary Fraction to Decimal Conversion

6
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

EXAMPLE : n = 110.101

Representation of Negative Integers

7
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

1’s Complement of Binary Number is computed by changing the bits 1 to 0 and the
bits 0 to 1. For example,
1’s complement of 101 is 010
1’s complement of 1011 is 0100
1’s complement of 1101100 is 0010011
2’s Complement of Binary Number is computed by adding 1 to the 1’s complement of
the binary number. For example,
2’s complement of 101 is 010 + 1 = 011
2’s complement of 1011 is 0100 + 1 = 0101
2’s complement of 1101100 is 0010011 + 1 = 0010100

SIGNED AND UNSIGNED NUMBERS


A binary number may be positive or negative. Generally, we use the symbol “+” and “−” to represent
positive and negative numbers, respectively. The sign of a binary number has to be represented using
0 and 1, in the computer. An n-bit signed binary number consists of two parts—sign bit and

8
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

magnitude. The left most bit, also called the Most Significant Bit (MSB) is the sign bit. The
remaining n-1 bits denote the magnitude of the number

In signed binary numbers, the sign bit is 0 for a positive number and 1 for a negative number. For
example, 01100011 is a positive number since its sign bit is 0, and, 11001011 is a negative number
since its sign bit is 1. An 8–bit signed number can represent data in the range −128 to +127 (–27to
+27−1). The left-most bit is the sign bit.

FRACTIONAL NUMBERS.
Fractional numbers, such as 12.34 and −0.001275, can also be represented in binary by using the
signed-integer techniques we have just described. To do that, however, first convert the number to
scientific notation:

where M is the mantissa, B is the exponent base (usually 2), and E is the exponent.
Example:Represent the decimal quantity 15.75.
Use 16 bits to represent the number, with 10 bits allocated for representing the mantissa and 6 bits for
the exponent. (The exponent base B is assumed to be 2 and is not explicitly stored.) Both the mantissa
and the exponent are signed integer numbers, so we can use either the sign/magnitude or two’s
complement notations that we just learned to represent each of these two fields. (In all the following
examples, we have chosen to use sign/magnitude notation.) In binary, the value 5 is 101. To represent
the fractional quantity 0.75
0.75 = 0.11
5.75 = 101.11

9
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

EXAMPLE : Determine the internal representation of the fraction −5/16.

MEMORY REPRESENTATION

10
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

● The computer memory stores different kinds of data like input data, output data, intermediate
results, etc., and the instructions. Binary digit or bit is the basic unit of memory. A bit is a single
binary digit, i.e., 0 or 1.
● A bit is the smallest unit of representation of data in a computer. However, the data is handled by
the computer as a combination of bits.
● A group of 8 bits form a byte.
● One byte can store 28, i.e., 256 different combinations of bits, and thus can be used to represent
256 different symbols. In a byte, the different combinations of bits fall in the range 00000000 to
11111111. A group of bytes can be further combined to form a word. A word can be a group of 2,
4 or 8 bytes.

Memory is logically organized as a linear array of locations. For a processor, the


range of the memory addresses is 0 to the maximum size of memory.

11
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

Binary Representation in Data Storage

● Text: Characters are encoded as binary numbers using standards like ASCII or
Unicode. Example: ○ A=01000001 in binary (ASCII).
● Images: Stored as a grid of pixels, each represented in binary (e.g., grayscale uses
8 bits per pixel).
● Audio: Sampled and quantized into binary values during analog-to-digital
conversion.

ASCII (AMERICAN STANDARD CODE FOR INFORMATION


INTERCHANGE)

• ASCII is a 7-bit character encoding standard used to represent text in computers, communication
systems, and other devices. It assigns numerical values to letters, digits, punctuation marks, and
control characters.
• The American Standard Code for Information Interchange (ASCII) is widely used in computers of
all types.
• ASCII codes are of two types—ASCII−7 and ASCII−8.
• ASCII-7 is a 7-bit standard ASCII code. In ASCII-7, the first 3 bits are the zone bits and the next
4 bits are for the digits. ASCII-7 allows 27 = 128 combinations. 128 unique
• ASCII-8 is an extended version of ASCII-7.
• ASCII-8 is an 8-bit code having 4 bits for zone and 4 bits for the digit.
• ASCII-8 allows 28 = 256 combinations. ASCII-8 represents 256 unique symbols. ASCII is
used widely to represent data in computers.
• The ASCII-8 code represents 256 symbols.
• Codes 0 to 31 represent control characters (non−printable), because they are used for
actions like, Carriage return (CR), Bell (BEL), etc.
• Codes 48 to 57 stand for numeric 0−9. o
• Codes 65 to 90 stand for uppercase letters A−Z.
• Codes 97 to 122 stand for lowercase letters a−z.
• Codes 128 to 255 are the extended ASCII codes.

Key Features of ASCII:

12
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

• 7-bit Encoding: Represents 128 characters (0-127).


• Extended ASCII (8-bit): Some systems use 8-bit ASCII (0-255) to include additional
symbols and characters.
• Widely Used: ASCII is the foundation for modern character encodings like UTF-8.

EXAMPLE 1: Encode the word “DATA” and convert the encoded value into binary
values which can be understood by a computer.
Answer:
ASCII value of D is 68 and its equivalent 7-bit binary code = 1000100
ASCII value of A is 65 and its equivalent 7-bit binary code = 1000001
ASCII value of T is 84 and its equivalent 7-bit binary code = 1010100
ASCII value of A is 65 and its equivalent 7-bit binary code = 1000001

EXAMPLE 2: Encode the string data “Good” into its binary representation using
ASCII/UTF-8.
Ans: 01000111 01101111 01101111 01100100

13
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

EXAMPLE 3: Encode the string data “Hello” into its binary representation using
ASCII/UTF-8.
Ans: 01001000 01100101 01101100 01101100 01101111

EXAMPLE 4: Decode the binary data “01101000 01100001 01101001” into its text
representation using ASCII/UTF-8.
Ans: hai
EXAMPLE 5: Decode the binary data “01101000 01100101 01101100 01101100
01101111” into its text representation using ASCII/UTF-8.
Ans: hello

EBCDIC (EXTENDED BINARY CODED DECIMAL INTERCHANGE CODE)

• It is an 8-bit character encoding system developed by IBM. It was primarily used on IBM
mainframes and midrange computers.
• EBCDIC codes are mainly used in the mainframe computers.
• 256 unique symbols are represented using EBCDIC code.
• It represents decimal numbers (0−9), lower case letters (a−z), uppercase letters (A−Z), Special
characters, and Control characters (printable and non−printable, e.g., for cursor movement,
printer vertical spacing, etc.).

Unicode

• Unicode is a universal character encoding standard for the representation of text which includes
letters, numbers and symbols in multi−lingual environments.
• The Unicode Consortium based in California developed the Unicode standard.
• Unicode uses 32 bits to represent a symbol in the data.
• Unicode allows 232 = 4164895296 (~ 4 billion) combination
• Unicode can uniquely represent any character or symbol present in any language like Chinese,
Japanese, etc. In addition to the letters; mathematical and scientific symbols are also represented
in Unicode codes.
• An advantage of Unicode is that it is compatible with the ASCII−8 codes. The first 256 codes in
Unicode are identical to the ASCII-8 codes.

14
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

• Unicode is implemented by different character encodings. UTF-8 is the most commonly used
encoding scheme. UTF stands for Unicode Transformation Format. UTF-8 uses 8 bits to 32 bits
per code
• Multiple Encoding Forms:
• UTF-8 (1-4 bytes per character) – Most widely used on the web.
• UTF-16 (2 or 4 bytes per character).
• UTF-32 (4 bytes per character)

ASCII Vs Unicode

Practice Questions :
1. What is the value of the 8-bit binary quantity 10101000 if it is interpreted
(a) as an unsigned integer and
(b) as a signed integer represented in sign/magnitude notation?
2. What does the unsigned decimal value 99 look like in binary using 8 bits?
3. What do the signed integers −300 and 1254 look like in binary using 10 bits and
sign/magnitude integer representation?

15
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

4. What is the value of the 8-bit binary quantity 10010111 when it is interpreted as a
sign/magnitude integer?
5. Using 4 bits and two’s complement representation, what is the binary
representation of the following signed decimal values:
a. +6
b. −3
6. Using 10 bits to represent the mantissa (sign/magnitude) and 6 bits for the exponent
(also sign/magnitude), show the internal representation of the following two values:
a. + 0.25
b. − 32 1/16

16
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

CPU ARCHITECTURE
Central Processing Unit (CPU) controls, coordinates and supervises the operations of the computer. It
is responsible for processing of the input data. The CPU is the brain of the computer, responsible
for executing instructions. A simplified conceptual block diagram of a CPU with memory is shown
in Figure

The computer unit is made up conceptually of three major components,


1. the arithmetic/logic unit (ALU) :-where data is held temporarily and where calculations take
place.
2. the control unit (CU):- controls and interprets the execution of instructions
3. memory.
● The ALU and CU together are known as the central processing unit (CPU).

Arithmetic Logic Unit (ALU):

● ALU consists of two units—arithmetic unit and logic unit.


● The arithmetic unit performs arithmetic operations on the data that is made available to it. Some
of the arithmetic operations supported by the arithmetic unit are—addition, subtraction,
multiplication and division.
● The logic unit of ALU is responsible for performing logic operations. Logic unit performs
comparisons of numbers, letters and special characters. Logic operations include testing for
greater than, less than or equal to condition.

17
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

● ALU performs arithmetic and logic operations, and uses registers to hold the data that is being
processed.
● Performs arithmetic operations (addition, subtraction, multiplication, division).
● Executes logical operations (AND, OR, NOT, XOR) for decision-making.
● Works directly with data fetched from registers or memory.

Control Unit (CU):

● The control unit of a computer does not do any actual processing of data. It organizes the
processing of data and instructions. It acts as a supervisor and, controls and coordinates the
activity of the other units of computer.
● Directs and coordinates the activities of the computer.
● Decodes instructions fetched from memory and sends control signals to other components
(ALU, memory, I/O).
● Ensures instructions are executed in the correct sequence.

• Registers:

o Small, high-speed storage locations inside the CPU.

o Temporarily hold data, instructions, or intermediate results.

o Common registers include the Accumulator (ACC) for operations, Instruction


Register (IR) for holding current instructions, and Program Counter (PC) for
tracking the next instruction.

• Accumulator (ACC) stores the result of arithmetic and logic operations.


• Instruction Register (IR) contains the current instruction most recently fetched.
• Program Counter (PC) contains the address of next instruction to be processed.
• Memory Address Register (MAR) contains the address of next location in the memory to be
accessed.
• Memory Buffer Register (MBR) temporarily stores data from memory or the data to be sent
to memory.
• Data Register (DR) stores the operands and any other data.

Memory

18
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

Memory stores data and instructions that the CPU needs to execute tasks. It is divided into:

• Primary Memory (RAM):


o Temporary storage that holds data and instructions while tasks are being executed.
o Volatile in nature; data is lost when the computer is turned off.

• Secondary Memory:
o Non-volatile storage like hard drives, SSDs, and external storage for long-term data
retention.

• Cache Memory:
o A small, fast memory inside or near the CPU.
o Holds frequently accessed data to speed up processing.

Input/Output (I/O) Devices


• Input Devices: Allow users to interact with the computer (e.g., keyboard, mouse, scanner).
• Output Devices: Display results of computations (e.g., monitor, printer, speakers).

Registers
Why are Registers Important?
Registers are crucial because they reduce the time the CPU spends accessing data from slower memory
types. By keeping data close to the CPU, they enhance performance and efficiency.
• Speed: Registers offer significantly faster access times compared to main memory (RAM),
leading to quicker instruction execution.
• Efficiency: By keeping frequently used data readily available, registers minimize the need to
constantly fetch data from slower memory locations.

19
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

• Registers are high-speed storage areas within the CPU, but have the least storage capacity.
Registers are not referenced by their address, but are directly accessed and manipulated by the
CPU during instruction execution.
• Registers store data, instructions, addresses and intermediate results of processing. Registers
are often referred to as the CPU’s working memory.
• The data and instructions that require processing must be brought in the registers of CPU before
they can be processed. For example, if two numbers are to be added, both numbers are brought
in the registers, added and the result is also placed in a register

• Accumulator (ACC) stores the result of arithmetic and logic operations.


• Instruction Register (IR) contains the current instruction most recently fetched.
• Program Counter (PC) contains the address of next instruction to be processed.
• Memory Address Register (MAR) contains the address of next location in the memory to be
accessed.
• Memory Buffer Register (MBR) temporarily stores data from memory or the data to be sent to
memory.
• Data Register (DR) stores the operands and any other data.
• The number of registers and the size of each (number of bits) register in a CPU helps to determine
the power and the speed of a CPU.
• The overall number of registers can vary from about ten to many hundreds, depending on the type
and complexity of the processor.
• The size of register, also called word size, indicates the amount of data with which the computer
can work at any given time. The bigger the size, the more quickly it can process data. The size of
a register may be 8, 16, 32 or 64 bits. For example, a 32–bit CPU is one in which each register is
32 bits wide and its CPU can manipulate 32 bits of data at a time. Nowadays, PCs have 32–bit or
64–bit registers.
• 32-bit processor and 64-bit processor are the terms used to refer to the size of the registers. Other
factors remaining the same, a 64-bit processor can process the data twice as fast as one with 32-bit
processor.

20
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

Relationship between MAR, MDR and Memory

• The output from the memory address register is passed to an address decoder.
• The output from the address decoder consists of a series of lines, each of which can light up the
bulbs in a single row of cells.
• Only one line at a time can be activated—specifically, the one corresponding to the decoded
address.
• The active line will light the bulbs that correspond to “1s”, leaving the “0s” dark.
The viewer therefore will see only the single group of cells that i

21
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

INSTRUCTION FORMAT AND ASSEMBLY LANGUAGE

Fetch–Execute Instruction Cycle

• The fetch execute cycle is a computer’s most basic operation.


• The instruction set is a specialized collection of instructions or tasks that the CPU is designed to
perform. It retrieves and executes instructions from the main memory.
• The Fetch–Execute Cycle, also known as the Instruction Cycle, is the fundamental process by
which a computer's Central Processing Unit (CPU) executes instructions.

• It consists of four main stages:


1. Fetch
• The CPU retrieves the next instruction from memory.
• The Program Counter (PC) holds the address of the next instruction.
• The instruction is fetched from RAM (memory) and stored in the Instruction Register (IR).
• The PC is incremented to point to the next instruction.
2. Decode
• The CPU interprets the instruction.
• The Control Unit (CU) decodes the instruction in the IR.
• The instruction is broken down into opcode (operation code) and operands (data or memory
locations).
3. Execute
• The CPU carries out the instruction.
• The Arithmetic Logic Unit (ALU) performs calculations if needed.
• The CPU may read or write data to memory.
• The results are stored in registers or memory.
4. Store (Write Back)
• The result is stored for future use.
• The output is written to memory or a register.
• The status flags are updated if necessary

22
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

• Every instruction must be fetched from memory before it can be executed. Therefore, the first step
in the instruction cycle always requires that the instruction must be fetched from memory.
• The address of the current instruction to be executed is identified by the value in the program
counter register
• The first step will be to transfer that value into the memory address register, so that the computer can
retrieve the instruction located at that address

• Following notation to indicate the transfer of a data value from one register to another:

Step 1: Transferred from the Program counter to the Memory Address Register.

Step 2: Transferred from the Memory Data Register to the Instruction Register.

The instruction register will hold the instruction through the rest of the instruction cycle.
Step 3: The remaining steps are instruction dependent. Let us consider the steps required to complete
a load instruction

The notation IR [address] is used to indicate that only the address part of the contents of the instruction
register is to be transferred.
Step 4: This step prepares the memory module to read the actual data that will be copied into the
accumulator

Step 5: The CPU increments the program counter, and the cycle is complete and ready to begin the
next instruction

23
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

The load instruction requires only five steps. Four of the steps simply involve the movement of data
from one register to another. and the new value is returned to the same register.
The fifth step is nearly as simple. It requires the addition of the value 1 to the contents of a register

The STORE instruction

The ADD instruction

Assume that the following values are present just prior to execution of this segment:

24
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

25
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

INSTRUCTION SET

• An instruction set is a collection of commands that a CPU can understand.


• These commands are written in machine language, made up of 1s and 0s.
• Instruction sets tell the CPU how to perform tasks.
• Instructions can be simple commands like read, write, or move.
• Instructions are made up of a specific number of bits.
• For instance, the CPU's instructions might be 8 bits, where the first 4 bits make up the operation
code that tells the computer what to do. The next 4 bits are the operand, which tells the computer
the data that should be used.
• Also, the length of an instruction set can vary from as few as 4 bits to many hundreds.

Classification of Instructions

• Privileged instructions: operating system can execute these instructions.


eg: HALT
• User accessible instructions: Programs that execute without privileges are said to execute in
user space.
• Computer manufacturers usually group the instruction set into various categories of instructions,
such as
• data movement instructions
• integer arithmetic instructions
• floating point arithmetic instructions
• shift and rotate instructions
• input/output instructions
• branch instructions
• special-purpose instructions.

Data Movement Instructions: Move data between registers, memory, and input/output
devices.
• MOV – Transfer data from one location to another
• LOAD – Load data from memory into a register
There may be a load byte instruction, a load half-word (2 bytes), a load word (4
bytes), and a load double word (8 bytes) within the same instruction set.
Eg: LOAD 1 --Load the contents of memory cell 1 into register R
• STORE – Store data from a register to memory
Eg: STORE A --Store the result into A
• PUSH/POP – Move data to/from the stack
Arithmetic Instructions

• CPU instruction set includes integer addition and subtraction.


Addition

26
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

• The content of operand are added to the content of the accumulator and the result is stored in
accumulator .
• ADD A,B
subtraction.
• Any 8 bit data or the contents of a register or contents of a memory location can be subtracted
from the contents of the accumulator.
• SUB A,B

Logical Instructions: Perform bitwise and logical operations.


• The AND instruction is used for supporting logical expressions by performing bitwise AND
operation.
• ANA – Logical AND: This instruction performs a logical AND operation between the
accumulator and a specified register or memory location, and stores the result in the
accumulator. For example, the instruction “ANA B” performs a logical AND operation between
the contents of the accumulator and the contents of the B register.
• The OR instruction is used for supporting logical expression by performing bitwise OR
operation.
• ORA – Logical OR: This instruction performs a logical OR operation between the accumulator
and a specified register or memory location, and stores the result in the accumulator. For
example, the instruction “ORA C” performs a logical OR operation between the contents of the
accumulator and the contents of the C register.

Single Operand Manipulation Instructions


These instructions operate on the value in a register, but some instruction sets provide similar
operations on memory values as well.
The instruction set will contain instructions for incrementing a value, for decrementing a value.

• Increment : INC increases a value by 1.


INC AX ; AX = AX + 1
• Decrement : DEC decreases a value by 1.

27
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

DEC AX ; AX = AX - 1

Shift and Rotate Instructions


• Shift and rotate operations have been used to implement multiplication and division.
• Shift instructions move the data bits left or right one or more bits.
• Rotate instructions also shift the data bits left or right, but the bit that is shifted out of the end is
placed into the vacated space at the other end.
• Depending on the design of the particular instruction set, bits shifted out the end of the word may be
shifted into a different register or into the carry or overflow flag bit.
• The data word being shifted might be logical or it might be numeric.
• Logical shift instructions simply shift the data as you would expect, and zeros are shifted in to replace
the bit spaces that have been vacated.
• Two different kinds of shifts are usually provided
• Logical shift instructions simply shift the data as you would expect, and zeros are
shifted in to replace the bit spaces that have been vacated.
• Arithmetic shift instructions are commonly used to multiply or divide the original
value by a power of 2.

28
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

INSTRUCTION WORD FORMAT

• The instruction word format defines how an instruction is structured in a CPU.


• Opcode (Operation Code): Specifies the operation to be performed (e.g., ADD, SUB, LOAD).
• Operands: Specifies registers, memory locations, or immediate values involved in the operation.
• Addressing Mode: Defines how operands are accessed
• The instruction word can be divided into an opcode and zero or more address fields.
• A simple 32-bit instruction format with one address field is shown in figure
• In this example, the 32 bits are divided into an 8-bit opcode and 24 bits of address field.

29
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

Explicit Source Address


An explicit source address is the memory location or register explicitly mentioned in an
instruction from which data is fetched for an operation. It defines where the operand (input
data) for an instruction is located.
Implicit Address
An implicit address is an address (register or memory location) that is not explicitly
mentioned in the instruction but is assumed by the CPU based on the instruction type
Types of Instruction Formats:
1. Zero-Address Instruction Format (Stack-based)
• No explicit operand fields;
• all operations use an implicit stack.
• Used in stack-based architectures.
• Example: PUSH A, ADD (adds top two stack values)
2. One-Address Instruction Format (Unary Instructions)
• One operand is specified explicitly;
• the other is implicitly the accumulator (AC).
• Common in early Accumulator-based architectures.
• Example: ADD A (AC = AC + A)

3. Two-Address Instruction Format (Binary Instructions)


• Specifies two operands: one source and one destination.
• Example: ADD A, B (A = B + A).
• MOV A,B

30
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

4. Three-Address Instruction Format(Ternary Instructions )


• Specifies three operands (source1, source2, destination).
• Used in General-Purpose Register (GPR) architectures.
• Example: ADD R1, R2, R3 (R3 = R1 + R2).
• MUL A, B, C ; C = A × B

ASSEMBLY LANGUAGE
Disadvantages of machine language
• It uses binary. There are no natural language words, mathematical symbols, or other
convenient mnemonics to make the language more readable.
• It allows only numeric memory addresses (in binary). A programmer cannot name an
instruction or a piece of data and refer to it by name.
• It is difficult to change. If we insert or delete an instruction, all memory addresses following
that instruction will change.
• It is difficult to create data. If a user wants to store a piece of data in memory, he or she
must compute the internal binary representation for that data item. These conversion algorithms
are complicated and time consuming.

31
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

Inorder to overcome the short comings of machine language, the programmers developed a
new language,called assembly language.
● Assembly languages created a more productive, user-oriented environment.
● Today, assembly languages are more properly called low-level programming
languages, which means they are closely related to the machine language.
● Each symbolic assembly language instruction is translated into exactly one binary
machine language instruction.
● A program written in assembly language is called the source program.
● The source program must be translated into a corresponding machine language
program,called the object program.
● This translation is carried out by a piece of system software called an assembler.
● Translators for high-level languages are called compilers.

There are three major advantages to writing programs in assembly language rather than
machine language:
• Use of symbolic operation codes rather than numeric (binary) ones
• Use of symbolic memory addresses rather than numeric (binary) ones
• Pseudo-operations that provide useful user-oriented services such as data generation

Fig:The translation/loading/execution process


Our hypothetical assembly language is composed of instructions in the following format:

32
GXEST203 Foundations of Computing: From Hardware Essentials to Web Design

label: op code mnemonic address field --comment

The comment field, preceded in our notation by a double dash (--), is not really part of the instruction.
It is a helpful explanation added to the instruction by a programmer and intended for readers of the
program. It is ignored by the machine during translation and execution.
Assembly languages allow the programmer to refer to op codes using a
symbolic name, called the op code mnemonic, rather than by a number. We can write op codes using
meaningful words like LOAD, ADD, and STORE rather than obscure binary codes like 0000, 0011,
and 0001.
we can attach a symbolic label to any instruction or piece of data in the program. The label then
becomes a permanent identification for this instruction or data, regardless of where it appears in the
program or where it may be moved in memory. A label is a name (followed by a colon to identify it as
a label) placed at the beginning of an instruction.

Structure of a Typical Assembly Language Program

Example Program
.BEGIN
LOAD R1, VALUE ; Load VALUE into Register R1

ADD R1, R2 ; Add R2 to R1 and store the result in R1


STORE R1, RESULT ; Store the result in memory
HALT ; Stop execution
.DATA
VALUE DW 10 ; Declare a variable VALUE with initial data 10
RESULT DW ? ; Reserve space for storing result
33
.END

You might also like