CS 0447 Introduction to Computer Programming Luís Oliveira
Fall 2020
Memory and Addresses
Original slides by: Jarrett Billingsley Modified with bits from: Bruce Childers, David Wilkinson
#4
Addresses Lus Oliveira Original slides by: Jarrett Billingsley - - PowerPoint PPT Presentation
#4 CS 0447 Introduction to Computer Programming Memory and Addresses Lus Oliveira Original slides by: Jarrett Billingsley Modified with bits from: Bruce Childers, David Wilkinson Fall 2020 Cla lass announcements Add/Drop period
CS 0447 Introduction to Computer Programming Luís Oliveira
Fall 2020
Original slides by: Jarrett Billingsley Modified with bits from: Bruce Childers, David Wilkinson
#4
Cla lass announcements
2
3
Memory addre resses
▪ where its first byte is
every piece of data really has two parts: an address and a value
▪ whew
4
Puttin ing a varia riable le in in memory ry
.data x: .word 4
Window is checked, what do you see?
5
name initial value type
Lo Load-store arc rchit itectures
▪ adds the contents of rcx to the value at address rsp-8
instructions: loads and stores (like in MIPS)
6
Registers Memory
lw
loads copy data from memory into CPU registers
sw
stores copy data from CPU registers into memory
Operatin ing on varia riable les in in memory (a (anim imated)
7
4 4 5 5
x
8
MIP IPS IS ISA: lo load and store in instructio ions fo for r word rds
lw t1, x # loads from variable x into t1 sw t1, x # stores from t1 into variable x
loads and stores
9
Registers Memory
lw sw
MIP IPS IS ISA: lo load and store in instructio ions fo for r word rds
la t1, x # loads the ADDRESS of x into t1
t1 will now contain 4: The address of variable x
lw t2, 0(t1) # the contents of x into t2
10
Addr Val
04 1 00 2 00 3 00 4 DE 5 C0 6 EF 7 BE 8 6C 9 34 A 00 B 01 C 02
x
This means: The address is the contents
Read, , modif ify, , writ rite
11
lw t0, x add t0, t0, 1 sw t0, x
It It re reall lly is is that sim imple le
12
Que uesti stion
s? 13
they the only size it can work with?
14
Small ller numeric ic
.data x: .word 4 => 0x00000004 y: .half 4 => 0x0004 z: .byte 4 => 0x04
15
lb t0, tiny # loads a byte into t0 sb t0, tiny # stores a byte into tiny
▪ ???
16
MIP IPS IS ISA: : lo loading and sto torin ing 8/16-bit valu lues
can I I get an ext xtensio ion? … no
10012 ➔ to 8 bits ➔ 0000 10012
10012 ➔ to 8 bits ➔ 1111 10012 00102 ➔ to 8 bits ➔ 0000 00102
▪ we'll learn about why this is important later in the course
17
18
E X P A N D V A L U E
31 00000000 00000000 00000000 00000000
10010000
31 11111111 11111111 11111111 10010000
If the byte is signed… what should it become?
31 00000000 00000000 00000000 10010000
If the byte is unsigned… what should it become?
lb does
sign extension.
lbu does
zero extension.
How does the CPU know whether it' it's sig igned or unsig igned
➔ Everything’s a number ➔ Everything's in binary (and hex is convenient shorthand) ➔ Numbers may not be numbers ➔ So, how does the computer know a number is a number?
19
20
Ho How does s the e CP CPU know whethe ether r it's 's si sign gned ed or unsi signed gned
21
▪ it doesn't – you have to use the right instruction.
shorter and just looks so nice and consistent…
31 10100010 00001110 11111111 00000100
Tru runcatio ion
number of bits to a smaller number
22
31 10100010 00001110 11111111 00000100
11111111 00000100
sh
23
What t is the e memory?
24
▪ maybe in the future it won't be temporary ▪ the line between system memory and persistent storage will fade away…
and using reside
Bytes, , bytes, , bytes
▪ Gee wonder where they got the idea ▪ Addresses are the offset from the beginning!
addressable machine
25
Addr Val
00 1 30 2 04 3 00 4 DE 5 C0 6 EF 7 BE 8 6C 9 34 A 00 B 01 C 02
How much memory?
how many bytes can your memory have?
▪ kiB = 210, MiB = 220, GiB = 230 etc.
▪ kB = 103, MB = 106, GB = 109 etc.
26
Word rds, , word rds, , word rds
▪ The byte at the smallest address
27
Addr Val
00 1 30 2 04 3 00 4 DE 5 C0 6 EF 7 BE 8 6C 9 34 A 00 B 01 C 02
28
A matter of f pers rspectiv ive
29
Addr Val
... ... 7 DE 6 C0 5 EF 4 BE ... ... …is it 0xBEEFC0DE? …is it 0xDEC0EFBE?
Endia ianness
is the rule used to decide what order to put the bytes in
30
0xDEC0EFBE 0xBEEFC0DE
big-endian means the “BIG address" contains the END-byte little-endian means the “LITTLE address“ contains the END-byteDE C0 EF BE
1 2 3
nothing to do with value of bytes, only order
Which ich is is better: li little or r big? ig?
▪ so little-endian for virtually everyone – cause x86 – Apple sillycone will use a bi-endien architecture: ARM architecture
31
*big endian is better
What DOESN'T endia ianness aff ffect?
× the arrangement of the bits within a byte
▪ note the bytes are still DE, C0 etc. × 1-byte values, arrays of bytes, ASCII strings…
× the ordering of bytes inside the CPU
32
0xBEEFC0DE 0xED0CFEEB 0xDEC0EFBE l l e H o H e l l o
Summary
33