comp sci 251 intro 1 computer organization and assembly language wing huen

14
Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Upload: carmel-snow

Post on 29-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro1

Computer organization and assembly language

Wing Huen

Page 2: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro2

Course goals

Instruction set architecture– Binary representation of data and instructions– Processor and memory organization

Page 3: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro3

Course goals

High-level language implementation– Variables– Control structures– Functions/methods

Page 4: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro4

Course goals

Hardware support of instruction set– Memory hierarchy (cache)– Pipelining

Page 5: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro5

Language hierarchy

Machine language– Instructions that processor can directly execute– Represented in binary (0’s and 1’s)– Different for each processor (Pentium, MIPS, PowerPC)– What is: 0000001100011010110000000100000?

Assembly language– Symbolic names for machine instructions– Example: add $12, $12, $13

High-level languages– Machine-independent– X = y + z;

Page 6: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro6

Language translation

High-level language

Assembly language

Machine language

compiler

assembler

Page 7: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro7

Data representation

Text and numbers stored in binary (0,1)

“Bit”: Binary digit – a single 0 or 1 “Byte”: string of eight bits

fundamental unit of computer memory

Page 8: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro8

Number Systems

Normal humans: use decimal (base ten)

Computer scientists: use alternatives– Binary (base two)– Hexadecimal (base sixteen)

Page 9: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro9

Number Systems

Decimal (base ten; digits 0..9)

85710 = 8×102 + 5×101 + 7×100

Binary (base two; digits 0..1)

110012 = 1×24 + 1×23 + 0×22 + 0×21 + 1×20

Page 10: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro10

Number Systems

Hexadecimal (base sixteen; digits 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f)

4d7a16 = 4×163 + 13×162 + 7×161 + 10×160

Convert the binary number

00000011000110101100000001000000 to Hexadecimal 0x031ac040

Page 11: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro11

Decimal binary conversionMethod #1

Write the number as a sum of powers of 2: 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 210, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, ...

Example: convert 5710 to binary57 = 32 + 25 = 32 + 16 + 9 = 32 + 16 + 8 + 1= 25 + 24 + 23 + 20

= 1 1 1 0 0 1two

Page 12: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro12

Decimal binary conversionMethod #2

Repeatedly divide by 2 until the quotient is 0 The remainders are the bits First remainder is least significant bit (lsb) Last remainder is most significant bit (msb)

Example: convert 5710 to binary57 / 2 = 28 r 1 …

Page 13: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro13

Hexadecimal binary conversion

Hexadecimal digit = shorthand for 4 bits

0000 0001 0010 0011 0100 0101 0110 0111 0 1 2 3 4 5 6 7

1000 1001 1010 1011 1100 1101 1110 1111 8 9 a b c d e f

Example: convert 6c4d16 to binary

Page 14: Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen

Comp Sci 251 Intro14

Addition algorithm

Works for any base

Work from right to left Add carry-in and two digits

one- or two-digit result Sum = least significant digit Carry out = most significant

digit

Examples:

95210

+ 7710

2f516 1112

+ 1c16 + 112