Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen
Comp Sci 251 Intro 2 Course goals Instruction set architecture – Binary representation of data and instructions – Processor and memory organization
Comp Sci 251 Intro 3 Course goals High-level language implementation – Variables – Control structures – Functions/methods
Comp Sci 251 Intro 4 Course goals Hardware support of instruction set – Memory hierarchy (cache) – Pipelining
Comp Sci 251 Intro 5 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: ? Assembly language – Symbolic names for machine instructions – Example: add $12, $12, $13 High-level languages – Machine-independent – X = y + z;
Comp Sci 251 Intro 6 Language translation High-level language Assembly language Machine language compiler assembler
Comp Sci 251 Intro 7 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
Comp Sci 251 Intro 8 Number Systems Normal humans: use decimal (base ten) Computer scientists: use alternatives – Binary (base two) – Hexadecimal (base sixteen)
Comp Sci 251 Intro 9 Number Systems Decimal (base ten; digits 0..9) = 8× × ×10 0 Binary (base two; digits 0..1) = 1× × × × ×2 0
Comp Sci 251 Intro 10 Number Systems Hexadecimal (base sixteen; digits 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f) 4d7a 16 = 4× × × ×16 0 Convert the binary number to Hexadecimal 0x031ac040
Comp Sci 251 Intro 11 Decimal binary conversion Method #1 Write the number as a sum of powers of 2: 2 0, 2 1, 2 2, 2 3, 2 4, 2 5, 2 6, 2 7, 2 8, 2 9, 2 10, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,... Example: convert to binary 57 = = = = = two
Comp Sci 251 Intro 12 Decimal binary conversion Method #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 to binary 57 / 2 = 28 r 1 …
Comp Sci 251 Intro 13 Hexadecimal binary conversion Hexadecimal digit = shorthand for 4 bits a b c d e f Example: convert 6c4d 16 to binary
Comp Sci 251 Intro 14 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: f c