Presentation 1
Presentation 1
Badharudheen P
Assistant Professor,
Dept. of CSE, MESCE, Kuttippuram
Syllabus
◼ 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
◼ The binary system is a way of representing data using 0s and 1s.
◼ This system is used by computers to represent all the data it works with.
◼ It has base 2 (two base numbers 0 and 1), these base numbers are called bits.
◼ In binary number system, group of 4 bits is known as Nibble, and a group of 8
bits is known as Byte.
◼ A thousand bytes form a Kilo-byte (Kb)
◼ A thousand Kilobytes form a Mega-byte (Mb)
◼ A thousand Megabytes form a Giga-byte (Gb) and so on (Terabyte (TB),
Petabyte (PB), Exabyte (EB) … ).
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.
◼ Steps
1. 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. Continue until the quotient is 0.
5. Read the remainders in reverse order to get the binary representation.
Decimal to Binary Conversion - Questions
◼ Convert the following decimal numbers into its equivalent binary.
◼ 278
◼ 145
◼ 362
◼ 1126
Floating Point Number to Binary
◼ To convert an integral part into
binary, just follow the previously
discussed method.
◼ To convert the fractional part to
binary, multiply fractional part
with 2 and take the one bit which
appears before the decimal point.
◼ Follow the same procedure with
after the decimal point (.) part until
it becomes 1.0.
Floating Point Number to Binary
◼ Example: Convert 4.25 to binary
◼ Integral Part is 4, its binary representation is (100)2
◼ Fractional part is .25
◼ 0.25 * 2 =0.50 //take 0 and move 0.50 to next step.
◼ 0.25 = (01)2
◼ Note:
◼ Some fractional part numbers will not end up with 1.0 with the above method.
◼ In floating number storage, the computer will allocate 23 bits for the fractional part. So, it's
enough to do the above method at max 23 times.
Floating Point to Binary - Questions
◼ Convert the following floating-point numbers into its equivalent binary.
◼ 10.75
◼ 2.25
◼ 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 to Decimal Conversion - Questions
◼ Convert the following binary numbers into its equivalent decimal.
◼ 1101
◼ 10011101
◼ 0010110011
◼ 1110110101
◼ 10111010
Binary Fraction to Decimal Conversion
A. Convert the integral part of binary to decimal equivalent
◼ Multiply each digit separately from left side of radix point till the first digit by 20, 21,
22,… respectively.
◼ Add all the result coming from step 1.
◼ Equivalent integral decimal number would be the result obtained in step 2.
B. Convert the fractional part of binary to decimal equivalent
◼ Divide each digit from right side of radix point till the end by 21, 22, 23, … respectively.
◼ Add all the result coming from step 1.
◼ Equivalent fractional decimal number would be the result obtained in step 2.
C. Add both integral and fractional part of decimal number.
Binary Fraction to Decimal Conversion
◼ Given a string of binary number n. Convert binary fractional n into its decimal
equivalent.
◼ Examples:
Input: n = 110.101
Output: 6.625
Input: n = 101.1101
Output: 5.8125
Binary Fraction to Decimal Conversion - Example
▪ Let's take an example for n = 110.101
Step 1: Conversion of 110 to decimal
=> 1102 = (1*22) + (1*21) + (0*20)
=> 1102 = 4 + 2 + 0
=> 1102 = 6, so equivalent decimal of binary integral is 6.
Step 2: Conversion of .101 to decimal
=> 0.1012 = (1*1/21) + (0*1/22) + (1*1/23)
=> 0.1012 = 1*0.5 + 0*0.25 + 1*0.125
=> 0.1012 = 0.625, so equivalent decimal of binary fractional is 0.625
Step 3: Add result of step 1 and 2.
=> 6 + 0.625 = 6.625
Binary Fraction to Decimal Conversion - Questions
◼ Convert the following binary fraction numbers into its equivalent decimal.
◼ 11.01
◼ 100.11
◼ 00101.100
◼ 111.011
◼ 1011.101
ASCII Code
◼ American Standard Code for Information Interchange.
◼ It is a character encoding standard that represents text using binary numbers.
◼ It is used in computers, telecommunications equipment, and other devices.
◼ uses 7-bit binary numbers to represent 128 characters.
◼ The first 33 ASCII code points are non-printing control characters, such as the
carriage return, line feed, and tab.
◼ The remaining 95 code points are printable characters, such as letters,
numbers, and punctuation.
ASCII Table
Example
◼ 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 - Encoding
◼ Encode the string data “Good” into its binary representation using
ASCII/UTF-8.
Ans: 01000111 01101111 01101111 01100100
◼ Encode the string data “Hello” into its binary representation using
ASCII/UTF-8.
Ans: 01001000 01100101 01101100 01101100 01101111
Example - Decoding
◼ Decode the binary data “01101000 01100001 01101001” into its text
representation using ASCII/UTF-8.
Ans: hai
◼ Control Unit: Make sure that all the other parts perform their tasks accurately
and at correct time.
◼ Instruction Register (IR): The IR holds the instruction which is just about to be
executed. The instruction from the PC is fetched and stored in IR. As soon as
the instruction is placed in IR, the CPU starts executing the instruction, and the
PC points to the next instruction to be executed.
Types of CPU Register
◼ Stack Pointer (SP): The stack PCs pointer points to the top of the stack, which
is a part of the memory used to store function calls and other operations.
◼ Flag Register: A flag register, also known as a status register or condition code
register, is a special type of register used to indicate the status of the CPU or
the outcome of various operations such as Zero Flag, Carry flag, Sign Flag,
Overflow Flag, Parity Flag, Auxiliary Carry Flag, and Interrupt Enable Flag.
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.
Activities of Instruction Set Commands
◼ Data handling and memory management: used when setting a register to a
specific value, copying data from memory to a register or vice versa, and
reading and writing data.
◼ Control flow activities: One example is branch, which instructs the system to
go to another location and execute commands there. Another is jump, which
moves to a specific memory location or address.
Types of Instructions
◼ Data Transfer 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
◼ STORE – Store data from a register to memory
◼ PUSH/POP – Move data to/from the stack
Store Decode
Back Instruction Cycle Instruction
Execute
Instruction
Instruction Execution Cycle
◼ Fetch:
◼ The CPU retrieves the instruction from memory.
◼ The instruction is stored at the address specified by the program counter (PC).
◼ The PC is then incremented to point to the next instruction in memory.
◼ Decode:
◼ The CPU interprets the instruction and determines what operation needs to be
performed.
◼ This involves identifying the opcode and any operands that are needed to execute
the instruction.
Instruction Execution Cycle
◼ Execute:
◼ The CPU performs the operation specified by the instruction.
◼ This may involve reading or writing data from or to memory, performing
arithmetic or logic operations on data, or manipulating the control flow of the
program.
◼ Format:
◼ LABEL: OPERATION CODE OPERAND
◼ Disadvantages:
◼ Machine dependent
◼ An intermediate translating program is required
◼ Cannot be executed in small sized computers
◼ Knowledge of hardware required.
Assembler