+ All Categories
Home > Documents > CS 230: Computer Organization and Assembly Language

CS 230: Computer Organization and Assembly Language

Date post: 07-Jan-2016
Category:
Upload: prince
View: 18 times
Download: 0 times
Share this document with a friend
Description:
CS 230: Computer Organization and Assembly Language. Aviral Shrivastava. Department of Computer Science and Engineering School of Computing and Informatics Arizona State University. Slides courtesy: Prof. Yann Hang Lee, ASU, Prof. Mary Jane Irwin, PSU, Ande Carle, UCB. Announcements. Quiz 2 - PowerPoint PPT Presentation
15
C M L C M L CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics Arizona State University Slides courtesy: Prof. Yann Hang Lee, ASU, Prof. Mary Jane Irwin, PSU, Ande Carle, UCB
Transcript
Page 1: CS 230: Computer Organization and Assembly Language

CMLCML

CS 230: Computer Organization and

Assembly LanguageAviral

ShrivastavaDepartment of Computer Science and

EngineeringSchool of Computing and Informatics

Arizona State University

Slides courtesy: Prof. Yann Hang Lee, ASU, Prof. Mary Jane Irwin, PSU, Ande Carle, UCB

Page 2: CS 230: Computer Organization and Assembly Language

CMLCML

Announcements

• Quiz 2– Complete Chapter 2

• MIPS Assembly Language Programming, including function calls– Thursday, Sept 24, 2009

• Project 2– MIPS Assembly Language Programming, including

function calls– Will take a day or two to program– Due tomorrow

Page 3: CS 230: Computer Organization and Assembly Language

CMLCML

CSE 230 Road map

• So far– Write any program in MIPS assembly

language– Convert into binary instructions

• Today– How are numbers represented– How are they added, subtracted,

multiplied divided

Page 4: CS 230: Computer Organization and Assembly Language

CML

Numbers• Bits are just bits (no inherent meaning)

– conventions define relationship between bits and numbers

• Unsigned Numbers– 0 - 231

• Large Numbers– Avogadro's number

• 6.0221415 × 1023 ~ 64 bits

• Signed Numbers– How to represent –ve numbers

• Fractions– How to represent

14159265.3

Page 5: CS 230: Computer Organization and Assembly Language

CMLCML

Unsigned Numbers• Representation

(d31 d30 … d2 d1 d0)2 = d31*231 + d30*230 + … d2*22 + d1 * 21 + d0*20

0000 0000 0000 0000 0000 0000 0000 0000 = 010

0000 0000 0000 0000 0000 0000 0000 0001 = 110

0000 0000 0000 0000 0000 0000 0000 0010 = 210

. . . . . . . . . .1111 1111 1111 1111 1111 1111 1111 1111 =

4,294,967,29510

• Minimum Number= 0 = (0000….0000)2

• Maximum Number= (1111….1111)2 = (1 0000….0000)2 – 1 = 232-1

32

Page 6: CS 230: Computer Organization and Assembly Language

CMLCML

Addition of Unsigned Numbers

• Addition 0 0 1 1 3 + 0 0 1 0 +2--------------------- 0 1 0 1 5

• What happens when– Addition results in a number that does

not fit in 32-bits• 232-1 + 232-1 = 2*232 – 2 = 233 -2 -- needs

33 bits– Overflow

Page 7: CS 230: Computer Organization and Assembly Language

CMLCML

Subtraction of Unsigned Numbers

• Subtraction 0 0 1 1 3 - 0 0 1 0 -2--------------------- 0 0 0 1 1

• What happens when– You subtract greater number from

smaller number• Need –ve numbers

Page 8: CS 230: Computer Organization and Assembly Language

CMLCML

Signed Numbers• One simple strategy

– Sign Magnitude Representation• Leftmost bit is sign bit• Rest 31-bits are unsigned

– Representation• (d31 d30 … d2 d1 d0)2 = (-1)*d31 + d30*230 + … d2*22 + d1 * 21 +

d0*20

– Number Range = -(231-1), …,-1,-0, +0,+1, …, +(231-1)• 2 zero’s

– How to find –ve of a number• Just change the sign-bit

– Addition & Subtraction• Add/Sub the 31-bits, and change the sign bit logically• Need a seamless way to perform these very frequent

operations

31-bit magnitude1-bit sign

Page 9: CS 230: Computer Organization and Assembly Language

CMLCML

2s Complement Representation

• Representation• (d31 d30 … d2 d1 d0)2 = d31*(-2)31 + d30*230 + … d2*22 + d1 * 21 +

d0*20

• Examples

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

0000 0000 0000 0000 0000 0000 0000 0001two = + 1ten

0000 0000 0000 0000 0000 0000 0000 0010two = + 2ten...

0111 1111 1111 1111 1111 1111 1111 1110two = + 2,147,483,646ten

0111 1111 1111 1111 1111 1111 1111 1111two = + 2,147,483,647ten

1000 0000 0000 0000 0000 0000 0000 0000two = – 2,147,483,648ten

1000 0000 0000 0000 0000 0000 0000 0001two = – 2,147,483,647ten

1000 0000 0000 0000 0000 0000 0000 0010two = – 2,147,483,646ten...

1111 1111 1111 1111 1111 1111 1111 1101two = – 3ten

1111 1111 1111 1111 1111 1111 1111 1110two = – 2ten

1111 1111 1111 1111 1111 1111 1111 1111two = – 1ten

Page 10: CS 230: Computer Organization and Assembly Language

CMLCML

Negate 2's Complement Number

• Negating a two's complement number: invert all bits

and add 1

– remember: “negate” and “invert” are quite different!• 0000 0000 0000 0000 0000 0000 0000 0010two = + 2ten

• 1111 1111 1111 1111 1111 1111 1111 1110two = – 2ten

• Converting n bit numbers into numbers with more than

n bits:

– MIPS 16 bit immediate gets converted to 32 bits for

arithmetic• "sign extension"

– copy the most significant bit (the sign bit) into the other

bits

0010 -> 0000 0010

1010 -> 1111 1010

Page 11: CS 230: Computer Organization and Assembly Language

CMLCML

Add 2’s Complement Numbers

• Just like unsigned numbers7 + 6 = 13

-4 + -5 = -9

0 1 1 10 1 1 0+1 1 0 1

11

1 1 0 01 0 1 1+0 1 1 1

1

00

0

11

1

Page 12: CS 230: Computer Organization and Assembly Language

CMLCML

Subtract 2’s Complement Numbers

• A – B = A + (-B) = A + (!B + 1)• Just like unsigned numbers

6 – 7 = 6 + (~7 + 1) = -1

-3 – 5 = -3 + (~(5)+1) = -81 1 0 10 1 0 1-1 0 0 0

0 1 1 00 1 1 1-1 1 1 1

001

0 1 1 01 0 0 1+1 1 1 1

011

101

1 1 0 11 0 1 1+1 0 0 0

111

Page 13: CS 230: Computer Organization and Assembly Language

CMLCML

Overflow• When result of operation too large to fit in 32-bits

7 – (-13) = 20

• Detect Overflows– Positive + Positive -> Negative– Negative + Negative -> Positive– Positive – Negative -> Negative– Negative – Positive -> Positive

• Consider the operations A + B, and A – B– Can overflow occur if B is 0 ?– Can overflow occur if A is 0 ?

0 1 1 10 0 1 1-

01

0 1 1 11 1 0 1+0 1 0 0

001

Page 14: CS 230: Computer Organization and Assembly Language

CMLCML

Effects of Overflow• An exception (interrupt) occurs

– Control jumps to predefined address for exception

– Interrupted address is saved for possible resumption

• Details based on software system / language– example: flight control vs. homework

assignment• Don't always want to detect overflow

– new MIPS instructions: addu, addiu, subu

note: addiu still sign-extends!note: sltu, sltiu for unsigned comparisons

Page 15: CS 230: Computer Organization and Assembly Language

CMLCML

Yoda says…

• Luke: I can’t believe it. • Yoda: That is why you fail


Recommended