0% found this document useful (0 votes)
37 views24 pages

Lecture10-Fixed Point Arithmetic

This document discusses fixed point arithmetic operations in microprocessors, including addition, subtraction, multiplication, and division. It provides examples of 8-bit and 16-bit binary addition and subtraction. It also explains various algorithms for unsigned and signed multiplication and division, such as repeated addition, shifting, and comparing bits. Flowcharts and code examples are provided to illustrate how to implement these fixed point arithmetic operations in a microprocessor.
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)
37 views24 pages

Lecture10-Fixed Point Arithmetic

This document discusses fixed point arithmetic operations in microprocessors, including addition, subtraction, multiplication, and division. It provides examples of 8-bit and 16-bit binary addition and subtraction. It also explains various algorithms for unsigned and signed multiplication and division, such as repeated addition, shifting, and comparing bits. Flowcharts and code examples are provided to illustrate how to implement these fixed point arithmetic operations in a microprocessor.
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/ 24

TK2633 :

MICROPROCESSOR &
INTERFACING

Lecture 10: Fixed Point


Arithmetic

Lecturer: Ass. Prof. Dr. Masri Ayob


Fixed Point Arithmetic.

 8-bit binary addition.


 Suppose that the ten 8-bit

numbers, stored at memory


locations 2800H through 2809H,
are added.
 To sum these data, an 8-bit

instructions are chosen.


 The ADD M instruction is chosen.

 Since this is to add 10 numbers,

the programme loop construct is


ideal for this problem.
 Figure illustrates the flowchart to

tackle the problem.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 2
8-bit binary addition
 The 8-bit binary addition listed in the example below, results in
a problem that the largest sum can be only 0FFH.
 This sum is appropriate only if 10 numbers are small, therefore
to avoid overflow for bigger sum operation, the 16-bit sum
operation will take place.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 3
8-bit binary addition
 Example of 16-bit summation.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 4
8-bit binary subtraction
 Suppose that two lists of
numbers, each 10H bytes long,
appear in the memory to be
subtracted.
 A programme must take the
number stored at LIST2 and
subtract it from the number
stored at LIST1.
 The difference must be stored at
a location in LIST2.
 This operation repeats 10H times
until all sets of numbers are
subtracted.
 Figure illustrates the process.
Written by: Ramizi Mohamed,
1/17/23 Edited by:Dr Masri Ayob 5
8-bit binary subtraction: Exercise

 There are two lists of numbers (LIST1 and LIST2),


each 10H bytes long, appear in the memory. Write
a program to take the number stored at LIST2 and
subtract it from the number stored at LIST1. The
difference must be stored at a location in LIST2.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 6
Unsigned Multiplication by Repeated
Addition

 Repeated addition is the


simplest method of
multiplication to
understand.
 Suppose to multiply two 8-
bit numbers, one number
can be used as the loop
counter.
 The other number can be
added the number of times
stored in the loop counter.
 Figure illustrates how the
number 6 can be multiplied
by 3.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 7
Unsigned Multiplication by Repeated Addition

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 8
Unsigned Constant Multiplication

 Instead of using the repeated addition technique


presented earlier, another technique often results in a
much faster multiplication, which using DAD instruction.
 The easiest way to multiply by 4 is by using the DAD H
instruction.
 Remember that if double HL twice, it is multiplied by 4.
 Example :

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 9
Unsigned Multiplication Algorithm
 The most flexible version of multiplication is the unsigned
multiplication shift and add algorithm.
 Observe the example below, the unsigned multiplication is
a combination of shifting the number followed by addition
for every shifted number.
 Figure below, illustrates the process of shifting and adding
number 9 and 15.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 10
Unsigned Multiplication Algorithm
 The flowchart example to perform the algorithm.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 11
Unsigned Multiplication Algorithm

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 12
Written by: Ramizi Mohamed,
1/17/23 Edited by:Dr Masri Ayob 13
Signed
Multiplication

 Modified
Flowchart
diagram to
perform
signed
multiplication.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 14
Signed Multiplication

 To do the signed multiplication, the multiplicand and


multiplier are exclusive ORed together.
 The result, which indicates the sign of the product, is
saved in the B register.
 Both numbers are then adjusted so that they are positive
before the MULT subroutine is called.
 Upon returning from the MULT subroutine, the sign of the
B register shows the sign of the product.
 For a negative result, the product in the HL register pair
must be negated to form a negative product.
 For a positive result, the product does not change.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 15
Signed Multiplication: Modification of the
previous program

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 16
Division by a constant

 If data are shifted to the left, they multiply by 2 for each bit
position of the shift.
 If data are shifted to the right, they divide by 2 for each bit
position of the shift.
 Knowing this as a technique used to multiply by a constant, a
technique can be developed so that a number can be divided
by any power of 2.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 17
Written by: Ramizi Mohamed,
1/17/23 Edited by:Dr Masri Ayob 18
Signed division by a constant
 Example shows how the signed contents of the accumulator are
divide by 4 with the result rounded.
 Notice that a shift left copies the sign bit into the carry flag before
shifting right twice.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 19
Unsigned division algorithm
 To divide a number by any integer value, a division
algorithm is normally used to develop a subroutine. The
division algorithm uses a combination of shifting left,
comparing, subtracting, and setting bits to perform binary
division.
 Below is an illustration of division algorithm.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 20
Unsigned
division
algorithm

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 21
Unsigned division algorithm

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 22
Signed division algorithm

 Signed binary
division is
treated in the
same manner
as signed
multiplication.

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 23
Thank you
Q&A

Written by: Ramizi Mohamed,


1/17/23 Edited by:Dr Masri Ayob 24

You might also like