Docsity

Computer Organization and Assembly Language - Notes | CS 0447, Study notes of Computer Science

Toggle sidebar
bg1
CS/COE0447: Computer Organization
and Assembly Language
and Assembly Language
Chapter 3
Chapter 3
Sangyeun Cho
Sangyeun Cho
Dept. of Computer Science
University of Pittsburgh
Five classic components
Five classic components
I am like a control
I am like a pack of
file folders
I am like a control
tower
file folders
I am like a conveyor
I exchange information
with outside world
belt + service stations
CS/CoE0447: Computer Organization and Assembly Language University of Pittsburgh
2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Computer Organization and Assembly Language - Notes | CS 0447 and more Study notes Computer Science in PDF only on Docsity!

CS/COE0447: Computer Organization

and Assembly Languageand Assembly Language

Chapter 3Chapter 3

Sangyeun ChoSangyeun Cho

Dept. of Computer Science University of Pittsburgh

Five classic componentsFive classic components

I am like a controlI am like a control I am like a pack offile folders tower file folders

I am like a conveyor

I exchange information with outside world belt + service stations

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh

Binary arithmeticBinary arithmetic

ƒ (Sounds scary)y

ƒ So far we studied

  • IInstruction set architecture basic t ti t hit t b i
  • MIPS architecture & assembly language

ƒ WW e will review binary arithmeticill i bi i h i

algorithms and their

implementations

ƒ Binary arithmetic will form the

basis for CPU’s datapath design

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 3

basis for CPU s datapath design

Binary number representationsBinary number representations

ƒ We looked at how to represent a number (in fact the valuep

represented by a number) in binary

  • Unsigned numbers – everything is positive

ƒ We will deal with more complicated cases

  • Negative numbers
  • RReal numbers (a.k.a. floating-point numbers) l b ( k fl ti i t b )

ƒ The first question: How do we represent a negative numberq p g

in decimal?

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh

Method 3: twoMethod 3: two s complement’s complement

ƒ (2 N^ – number)

• A + (-A) = 2N
  • Given a number A, it’s negation is done by (1111…1111 – A) + 1
  • In fact, simple bit-by-bit inversion followed by adding 1 will give the same magnitude number with a different signsame-magnitude number with a different sign
  • Examples, assume 4-bit representation 0000 0 0011 3 1001 - 1111 - 1000?

ƒ PP ropertiesti

  • There is a single 0
  • There are unequal # of positive and negative numbers

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 7

SummarySummary

Code Sign-Magnitude 1’s Complement 2’s Complement 000 +0 +0 + 001 +1 +1 + 010 +2 +2 + 011 +3 +3 + 100 -0 -3 - 101101 -1-1 -2-2 -3- 110 -2 -1 - 111 -3 -0 -

ƒ Issues
  • of zeros

  • Balance A ith ti l ith i l t ti

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh

  • Arithmetic algorithm implementation

When NWhen N = 32 32

ƒ If we use the two’s complement method

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 9

TwoTwo s complement operations’s complement operations

ƒ Negatingg g

  • Invert all bits and add 1
  • This operation is equivalent to subtracting the number from 2N^ (why?)

ƒ Converting an N-bit number into an M-bit number, M>N

  • E.g., MIPS 16-bit immediate (it’s a signed number) converted into a 32 bit number32-bit number
  • This operation is called sign-extension
  • E.g., from 4-bit encoding to 8-bit encoding 00100010 ⇒⇒ 0000 00100000 0010 1010 ⇒ 1111 1010
  • What is zero-extension?

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh

What is zero extension?

What happens on overflow?What happens on overflow?

ƒ The CPU can

  • Generate an exception (what is an exception?)
  • Set a flag in the status register (what is the status register?)
  • Do nothingg

ƒ Languages may have different notions about overflow

ƒ Do we have overflows in the case of unsigned, always

positive numbers?p

  • Example: addu, addiu, subu

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 13

MIPS exampleMIPS example

ƒ I looked at the MIPS32 instruction set manual

ƒ ADD, ADDI instructions generate an exception on overflow

ƒ ADDU, ADDIU are silent

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh

C language exampleC language example

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 15

SubtractionSubtraction

ƒ We know how to add

ƒ We know how to negate a

number

ƒ We will use the above two

known operations to perform

subtraction

ƒ AA – B = A + (-B)B A + ( B)

ƒ The hardware used for

addition can be extended to

handle subtraction!

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh

handle subtraction!

NN bit ripple carry adder-bit ripple-carry adder

(0)

carry in at each stage

(0) (1) (1) (0) (0)

0 0 1 1 1

0 0 1 1 0

(0) 0 (0) 1 (1) 1 (1) 0 (0) 1

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 19

carry out at each stage

Describing a singleDescribing a single bit adder-bit adder

ƒ A “truth” table will tell us about the operation of a single-bitp g

adder

Input Output A B C (^) in C (^) out S 0 0 0 0 0 0 0 1 0 1 00 11 00 00 11 0 1 1 1 0 1 0 0 0 1 11 00 11 11 00 1 1 0 1 0 1 1 1 1 1

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh

MultiplicationMultiplication

ƒ More complicated than additionp

  • A straightforward implementation will involve addition and shifting

ƒƒ AA “more complex operation” impliesmore complex operation implies

  • More area (on silicon) and/or
  • More time (more clock cycles or longer clock cycle time)

ƒ Let’s begin from a simple, straightforward method

  • For now, consider only unsigned numbers!y g

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 21

Straightforward algorithmStraightforward algorithm

01010010 (multiplicand) xx 0110110101101101 (multiplier)(multiplier)

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh

Hardware design 3Hardware design 3

32-bit ALU

64-bit shift register

Removed a 32-bit shift register!

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 25

g

ExampleExample

ƒ Let’s do 0010×0110 (2×6), unsignedg

Iteration Multiplicand

Implementation 3 Step Product 0 0010 initial values 0000 0110

1 0010

1: 0 -> no op (^) 0000 0110 2: shift right (^) 0000 0011

2 0010

1: 1 -> product = product + multiplicand 0010 0011 2: shift right 0001 0001 1: 1 -> product = 3 0010 product + multiplicandproduct + multiplicand^ 0011 0001 2: shift right 0001 1000

4 0010

1: 0 -> no op 0001 1000 2: shift right 0000 1100

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh

2: shift right 0000 1100

BoothBooth s encoding’s encoding

ƒ Three symbols to represent a binary number: {1,0,-1}
ƒ Examples (8-bit encoding)

11111111 (two’s complement) 0000000 1 (Booth’s encoding)0000000-1 (Booth s encoding)

  • 14 00001110 (two’s complement) 000100-10 (Booth’s encoding)
ƒ Bit transitions in number (in two’s complement encoding) show
how Booth’s encoding works
  • 0 to 0 (from right to left): 00 to 0 (from right to left): 0
  • 0 to 1: -
  • 1 to 1: 0
  • 1 to 0: 1

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 27

BoothBooth s encoding’s encoding

ƒ Key pointy p

  • A “1” in he multiplier implies an addition operation
  • If you have many “1”s – that means many addition operations

ƒ Booth’s encoding is useful because it can reduce the number

of addition operations you have to perform

ƒ With Booth’s encoding, partial results are obtained by

  • Adding multiplicandg p
  • Adding 0
  • Subtracting multiplicand

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh