Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Binary Arithmetic: 2's Complement, Multiplication, Division and Representations, Slides of Number Theory

The topics of binary arithmetic including 2's complement for signed numbers, addition and subtraction, multiplication, division, and alternative representations. It explains the advantages of 2's complement and discusses the discarded sign-and-magnitude and one's complement representations. The document also provides examples and algorithms for binary multiplication and division.

Typology: Slides

2021/2022

Uploaded on 09/12/2022

maya-yct
maya-yct 🇬🇧

4.8

(9)

217 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Lecture 8: Binary Multiplication & Division
Today’s topics:
Addition/Subtraction
Multiplication
Division
Reminder: get started early on assignment 3
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Binary Arithmetic: 2's Complement, Multiplication, Division and Representations and more Slides Number Theory in PDF only on Docsity!

2’s Complement – Signed Numbers^ 0000 0000 0000 0000 0000 0000 0000 0000

= 0two ten 0000 0000 0000 0000 0000 0000 0000 0001

= 1two ten …0111 1111 1111 1111 1111 1111 1111 1111

(^31) = 2-1two 1000 0000 0000 0000 0000 0000 0000 0000

(^31) = -2two 1000 0000 0000 0000 0000 0000 0000 0001

(^31) = -(2– 1)two 1000 0000 0000 0000 0000 0000 0000 0010

(^31) = -(2– 2)two …1111 1111 1111 1111 1111 1111 1111 1110

= -2two 1111 1111 1111 1111 1111 1111 1111 1111

= -1two Why is this representation favorable?Consider the sum of 1 and -2 …. we get -1Consider the sum of 2 and -1 …. we get +1This format can directly undergo addition without any conversions!Each number represents the quantity^31 x-2^ + x^231

30 29 + x^2 + … + x^29

1 02 + x^2 1

Addition and Subtraction^ • Addition is similar to decimal arithmetic• For subtraction, simply add the negative number – hence,subtract A-B involves negating B’s bits, adding 1 and A

Overflows^ • For an unsigned number, overflow happens when the last carry (1)cannot be accommodated• For a signed number, overflow happens when the most significant bitis not the same as every bit to its left^ ^ when the sum of two positive numbers is a negative result^ ^ when the sum of two negative numbers is a positive result^ ^ The sum of a positive and negative number will never overflow• MIPS allows addu and subu instructions that work with unsignedintegers and never flag an overflow – to detect the overflow, otherinstructions will have to be executed

HW Algorithm 1^ In every step• multiplicand is shifted• next bit of multiplier is examined (also a shifting step)• if this bit is 1, shifted multiplicand is added to the product

HW Algorithm 2^ • 32-bit ALU and multiplicand is untouched• the sum keeps shifting right• at every step, number of bits in product + multiplier = 64,hence, they share a single 64-bit register

MIPS Instructions^ mult^ $s2, $s

computes the product and storesit in two “internal” registers thatcan be referred to as hi and lo

mfhi^ $s^

moves the value in hi into $s

mflo^ $s^

moves the value in lo into $s

Similarly for multu

Fast Algorithm

  • The previous algorithmrequires a clock to ensure thatthe earlier addition hascompleted before shifting• This algorithm can quickly setup most inputs – it then has towait for the result of each addto propagate down – fasterbecause no clock is involved-- Note: high transistor cost

Division

1001 Quotientten^

Divisor^1000

|^1001010 ten^

Dividendten^

^0001000000

^0000100000

^0000001000

Quo:^0

At every step,• shift divisor right and compare it with current dividend• if divisor is larger, shift 0 as the next bit of the quotient• if divisor is smaller, subtract to get new dividend and shift 1as the next bit of the quotient

Divide Example^ • Divide 7^ (0000 0111ten^

) by 2(0010twoten^

)two Initial values 0 1 2 3 4 5

RemainderDivisor Quot Step Iter

Hardware for Division^ A comparison requires a subtract; the sign of the result isexamined; if the result is negative, the divisor must be added back

Efficient Division

Convention: Dividend and remainder have the same signQuotient is negative if signs disagreeThese rules fulfil the equation above

  • Lecture 8: Binary Multiplication & Division • Today’s topics:  Addition/Subtraction  Multiplication  Division• Reminder: get started early on assignment
  • Divisions involving Negatives • Simplest solution: convert to positive and adjust sign later• Note that multiple solutions exist for the equation:Dividend = Quotient x Divisor + Remainder+7 div +
  • Quo = +
  • Rem = +
  • -7 div +
  • Quo = -
  • Rem = -
  • +7 div -
  • Quo = -
  • Rem = +
  • -7 div -
  • Quo = +
  • Rem = -

Title^ • Bullet