Docsity

Introduction To Computer System Bits Bytes And Integers, Lecture Slide - Computer Science, Slides of Computer System Design and Architecture

Partial preview of the text

Download Introduction To Computer System Bits Bytes And Integers, Lecture Slide - Computer Science and more Slides Computer System Design and Architecture in PDF only on Docsity!

Bits, Bytes, and Integers

15-­‐213: Introduc0on to Computer Systems

nd

Lecture, Aug. 26, 2010

Instructors:

Randy Bryant and Dave O’Hallaron

Today: Bits, Bytes, and Integers

 Represen6ng informa6on as bits

 Bit-­‐level manipula6ons

 Integers

 Representa0on: unsigned and signed  Conversion, cas0ng  Expanding, trunca0ng  Addi0on, nega0on, mul0plica0on, shiLing

 Summary

Encoding Byte Values

 Byte = 8 bits

 Binary 00000000 2 to 11111111 2  Decimal: 0 10 to 255 10  Hexadecimal 00 16 to FF 16

 Base 16 number representa0on

 Use characters ‘0’ to ‘9’ and ‘A’ to ‘F’

 Write FA1D37B 16 in C as

  • 0xFA1D37B
  • 0xfa1d37b

A 10 1010

B 11 1011

C 12 1100

D 13 1101

E 14 1110

F 15 1111

Byte-­‐Oriented Memory Organiza6on

 Programs Refer to Virtual Addresses

 Conceptually very large array of bytes  Actually implemented with hierarchy of different memory types  System provides address space private to par0cular “process”

 Program being executed

 Program can clobber its own data, but not that of others

 Compiler + Run-­‐Time System Control Alloca6on

 Where different program objects should be stored  All alloca0on within single virtual address space

Word-­‐Oriented Memory Organiza6on

 Addresses Specify Byte

Loca6ons

 Address of first byte in word  Addresses of successive words differ

by 4 (32-­‐bit) or 8 (64-­‐bit)

32-bit! Words! Bytes! Addr.! 0012 0013 0014 0015 64-bit! Words! Addr! =! ?? Addr! =! ?? Addr! =! ?? Addr! =! ?? Addr! =! ?? Addr! =! ?? 0000 0004 0008 0012 0000 0008

Data Representa6ons

  • C Data Type Typical 32-bit Intel IA32 x86-
  • char
  • short
  • int
  • long
  • long long
  • float
  • double
  • long double 8 10/12 10/
  • pointer

Byte Ordering Example

 Big Endian

 Least significant byte has highest address

 LiSle Endian

 Least significant byte has lowest address

 Example

 Variable x has 4-­‐byte representa0on 0x  Address given by &x is 0x 0x100 0x101 0x102 0x 01 23 45 67 0x100 0x101 0x102 0x 67 45 23 01 Big Endian! Little Endian!

Address !Instruction Code !Assembly Rendition! 8048365: 5b pop %ebx 8048366: 81 c3 ab 12 00 00 add $0x12ab,%ebx 804836c: 83 bb 28 00 00 00 00 cmpl $0x0,0x28(%ebx)

Reading Byte-­‐Reversed Lis6ngs

 Disassembly

 Text representa0on of binary machine code  Generated by program that reads the machine code

 Example Fragment

 Deciphering Numbers

 Value: 0x12ab  Pad to 32 bits: 0x000012ab  Split into bytes: 00 00 12 ab  Reverse: ab 12 00 00

show_bytes Execu6on Example

int a = 15213;

printf("int a = 15213;\n");

show_bytes((pointer) &a, sizeof(int));

Result (Linux):!

int a = 15213;

0x11ffffcb8 0x6d

0x11ffffcb9 0x3b

0x11ffffcba 0x

0x11ffffcbb 0x

Represen6ng Integers

Decimal:! 15213 Binary: 0011 1011 0110 1101 Hex: 3 B 6 D 6D 3B 00 00 IA32, x86-64! 3B 6D

Sun!

int A = 15213;

C

FF

FF

IA32, x86-64! C 93

FF

FF

Sun! Twoʼs complement representation! (Covered later)!

int B = -15213;

long int C = 15213;

6D

3B

x86-64! 3B 6D

Sun! 6D 3B 00 00

IA32!

Represen6ng Strings

 Strings in C

 Represented by array of characters  Each character encoded in ASCII format

 Standard 7-­‐bit encoding of character set

 Character “0” has code 0x

  • Digit i has code 0x30+i  String should be null-­‐terminated

 Final character = 0

 Compa6bility

 Byte ordering not an issue Linux/Alpha! Sun! 31 38 32 34 33 00

Today: Bits, Bytes, and Integers

 Represen6ng informa6on as bits

 Bit-­‐level manipula6ons

 Integers

 Representa0on: unsigned and signed  Conversion, cas0ng  Expanding, trunca0ng  Addi0on, nega0on, mul0plica0on, shiLing

 Summary

Applica6on of Boolean Algebra

 Applied to Digital Systems by Claude Shannon

 1937 MIT Master’s Thesis  Reason about networks of relay switches

 Encode closed switch as 1, open switch as 0

A"

~A"

~B"

B"

Connection when!

A&~B | ~A&B!

A&~B!

~A&B! = A^B!

General Boolean Algebras

 Operate on Bit Vectors

 Opera0ons applied bitwise

 All of the Proper6es of Boolean Algebra Apply

^ 01010101