Docsity

Memory & Data I: Hardware, Data Representation, and Addressing in Computer Systems, Cheat Sheet of Mathematics

Partial preview of the text

Download Memory & Data I: Hardware, Data Representation, and Addressing in Computer Systems and more Cheat Sheet Mathematics in PDF only on Docsity!

Memory, Data, & Addressing I

Roadmap

**car *** c = malloc(sizeof( car )); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100); c.setGals(17); float mpg = c.getMPG(); get_mpg: pushq %rbp movq %rsp, %rbp ... popq %rbp ret C: Java: Assembly language: Machine code: 0111010000011000 100011010000010000000010 1000100111000010 110000011111101000011111 Computer system: OS: Memory & data Integers & floats x86 assembly Procedures & stacks Executables Arrays & structs Memory & caches Processes Virtual memory Memory allocation Java vs. C

Hardware: Physical View

CPU

(empty slot)

USB…
I/O

controller Storage connections Memory

Hardware: Logical View

CPU Memory Disks (^) Net USB^ Etc. Bus

Aside: Why Base 2?

❖ Electronic implementation

▪ Easy to store with bi-stable elements

▪ Reliably transmitted on noisy and inaccurate wires

❖ Other bases possible, but not yet viable:

▪ DNA data storage (base 4: A, C, G, T) is a hot topic

▪ Quantum computing

0.0V 0.5V 2.8V 3.3V 0 1 0

Binary Encoding Additional Details

❖ Because storage is finite in reality, everything is

stored as “fixed” length

▪ Data is moved and manipulated in fixed-length chunks

▪ Multiple fixed lengths ( e.g. 1 byte, 4 bytes, 8 bytes)

▪ Leading zeros now must be included up to “fill out” the fixed

length

❖ Example: the “eight-bit” representation of the

number 4 is 0b

Least Significant Bit (LSB) Most Significant Bit (MSB)

Hardware: 351 View (version 1)

Memory

CPU

take 469 registers i-cache

data

instructions

❖ More CPU details:

▪ Instructions are held temporarily in the instruction cache

▪ Other data are held temporarily in registers

❖ Instruction fetching is hardware-controlled

❖ Data movement is programmer-controlled (assembly)

Hardware: 351 View (version 1)

Memory

CPU

take 469 registers i-cache

data

instructions

❖ We will start by learning about Memory

How does a program find its data in memory?

Peer Instruction Question

❖ If we choose to use 4-bit addresses, how big is our

address space?

▪ i.e. How much space can we “refer to” using our addresses?

A. 1 6 bits

B. 1 6 bytes

C. 4 bits

D. 4 bytes

E. We’re lost…

Machine “Words”

❖ Instructions encoded into machine code (0’s and 1’s)

▪ Historically (still true in some assembly languages), all

instructions were exactly the size of a word

❖ We have chosen to tie word size to address size/width

▪ word size = address size = register size

▪ word size = 𝑤 bits → 2

𝑤 addresses

❖ Current x86 systems use 64 - bit (8-byte) words

▪ Potential address space: 𝟐

𝟔𝟒 addresses 2 64 bytes  1.8 x 10 19 bytes = 18 billion billion bytes = 18 EB (exabytes)

▪ Actual physical address space: 48 bits

Address of a Word = Address of First Byte in the Word

❖ Addresses still specify locations of bytes in memory ▪ Addresses of successive words differ by word size (in bytes): e.g. 4 (32-bit) or 8 (64-bit) ▪ Address of word 0, 1, … 10? ❖ Address of word = address of first byte in word ▪ The address of any chunk of memory is given by the address of the first byte ▪ Alignment 32 - bit Words Bytes 64 - bit Words Addr = ?? Addr = ?? Addr = ?? Addr = ?? Addr = ?? Addr = ?? 0000 0004 0008 0012 0000 0008 0x 0x 0x 0x 0x 0x 0x 0x 0x 0x 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F Addr. (hex)

A Picture of Memory (64-bit word view)

❖ A “64-bit (8-byte) word-aligned” view of memory:

▪ In this type of picture, each row is composed of 8 bytes

▪ Each cell is a byte

▪ A 64 - bit pointer

will fit on one row 0x 0x 0x 0x 0x 0x 0x 0x 0x 0x 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x one word Address

Addresses and Pointers

❖ An address refers to a location in memory

❖ A pointer is a data object that holds an address

▪ Address can point to any data

❖ Value 504 stored at

address 0x

▪ 50410 = 1F8 16

= 0x 00 ... 00 01 F

❖ Pointer stored at

0x38 points to

address 0x

0x 0x 0x 0x 0x 0x 0x 0x 0x 0x Address 00 00 00 00 00 00 01 F 00 00 00 00 00 00 00 08 64 - bit example (pointers are 64-bits wide) big-endian

Addresses and Pointers

❖ An address refers to a location in memory

❖ A pointer is a data object that holds an address

▪ Address can point to any data

❖ Pointer stored at

0x48 points to

address 0x

▪ Pointer to a pointer!

❖ Is the data stored

at 0x08 a pointer?

▪ Could be, depending

on how you use it 0x 0x 0x 0x 0x 0x 0x 0x 0x 0x Address 00 00 00 00 00 00 01 F 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 38 64 - bit example (pointers are 64-bits wide) big-endian