Computer Internals and Memory Systems

undefined
 
CS52 MACHINE
 
David Kauchak
CS 52 – Spring 2017
 
Admin
 
Midterm 1
Assignment 3
Assignment 4
 
Examples from this lecture
 
http://www.cs.pomona.edu/~dkauchak/classes/cs52/examples/cs52machine/
 
Computer internals
 
Computer internals simplified
 
What does it stand
for?
What does it do?
 
CPU
 
RAM
 
What does
it stand for?
What does
it do?
 
Computer internals simplified
 
(
C
entral 
P
rocessing
U
nit,
aka “
the processor
”)
 
CPU
 
RAM
 
(
R
andom 
A
ccess
M
emory,
aka “
memory
or “
main
memory”
)
 
Does all the work!
 
Temporary storage
 
Computer internals simplified
 
CPU
 
RAM
 
hard drive
 
“the computer”
 
Why do we need a hard drive?
 
Computer internals simplified
 
CPU
 
RAM
 
hard drive
 
“the computer”
 
-
Persistent memory
-
RAM only stores data while it has power
 
Computer simplified
 
hard drive
 
media drive
 
CPU
 
RAM
 
“the computer”
 
display
 
network
 
input devices
Inside the CPU
CPU
processor
registers
processor: does the work
registers: local, fast memory slots
 
Why all these levels of memory?
 
Memory speed
Memory
RAM
010101111000101000010010 …
 
What is a byte?
 
?
 
Memory
 
RAM
 
01010111 10001010 00010010 …
 
byte = 8 bits
byte is abbreviated as B
 
My laptop has 16GB (gigabytes) of memory.  How many bits is that?
 
Memory sizes
 
My laptop has 16GB (gigabytes) of memory.  How many bits is that?
 
Memory sizes
 
~128 billion bits!
 
Memory
 
RAM
 
01010111
10001010
00010010
01011010
 
Memory is byte addressable
 
address
 
0
1
2
3
 
Memory
 
RAM
 
01010111
10001010
00010010
01011010
 
Memory is organized into “words”, which
is the most common functional unit
 
address
 
0
1
2
3
 
Memory
 
RAM
 
10101011 10001010 00010010 01011010
11001011 00001110 01010010 01010110
10111011 10010010 00000000 01110100
 
Most modern computers use 32-bit (4 byte)
or 64-bit (8 byte) words
 
address
 
0
4
8
...
 
32-bit words
 
Memory in the CS52 Machine
 
RAM
 
10101011 10001010
00010010 01011010
11001011 00001110
 
We’ll use 16-bit words for our model (the
CS52 machine)
 
address
 
0
2
4
...
 
16-bit words
 
CS52 machine
 
CPU
 
processor
 
registers
 
ic
 
r0
 
r1
 
r2
 
r3
 
instruction counter
(location in memory of the next
 instruction in memory)
 
holds the value 0 (read only)
 
-
general purpose
-
read/write
undefined
 
ic
 
r0
 
r1
 
r2
 
r3
 
instruction counter
(location in memory of the next
 instruction in memory)
 
holds the value 0 (read only)
 
-
general purpose
-
read/write
 
CS52 machine instructions
 
CPU
 
processor
 
registers
 
What types of operations might
we want to do (think really basic)?
 
CS52 machine code
 
Four main types of instructions
1.
math
2.
branch/conditionals
3.
memory
4.
control the machine (e.g. stop it)
 
undefined
 
instruction name
 
arguments
undefined
 
instruction name
 
arguments
 
instruction/operation name
(always three characters)
undefined
 
instruction name
 
arguments
 
operation arguments
R = register (e.g. r0)
S = signed number (byte)
undefined
 
instruction name
 
arguments
 
1
st
 R: 
  
register where the answer will go
2
nd
 R: 
 
register of first operand
3
rd
 S/R:
 
register/value of second operand
undefined
 
add r1 r2 r3
 
What does this do?
 
1
st
 R: 
  
register where the answer will go
2
nd
 R: 
 
register of first operand
3
rd
 S/R:
 
register/value of second operand
undefined
 
add r1 r2 r3
 
r1 = r2 + r3
 
Add contents of registers r2 and
r3 and store the result in r1
 
1
st
 R: 
  
register where the answer will go
2
nd
 R: 
 
register of first operand
3
rd
 S/R:
 
register/value of second operand
undefined
 
add r2 r1 10
 
What does this do?
 
1
st
 R: 
  
register where the answer will go
2
nd
 R: 
 
register of first operand
3
rd
 S/R:
 
register/value of second operand
undefined
 
add r2 r1 10
 
r2 = r1 + 10
 
Add 10 to the contents of
register r1 and store in r2
 
1
st
 R: 
  
register where the answer will go
2
nd
 R: 
 
register of first operand
3
rd
 S/R:
 
register/value of second operand
undefined
 
add r1 r0 8
neg r2 r1
sub r2 r1 r2
 
What number is in r2?
 
1
st
 R: 
  
register where the answer will go
2
nd
 R: 
 
register of first operand
3
rd
 S/R:
 
register/value of second operand
undefined
 
add r1 r0 8
neg r2 r1
sub r2 r1 r2
 
r1 = 8
 
r2 = -8, r1 = 8
 
r2 = 16
 
1
st
 R: 
  
register where the answer will go
2
nd
 R: 
 
register of first operand
3
rd
 S/R:
 
register/value of second operand
 
sto = save data in register TO memory
loa = put data FROM memory into a register
 
Accessing memory
 
sto r1 r2  ; store the contents of r1 to mem[r2]
loa r1 r2 ; get data from mem[r2] and put into r1
 
sto = save data in register TO memory
loa = put data FROM memory into a register
 
Special cases:
-
saving TO (sto) address 0 prints
-
reading from (loa) address 0 gets input from user
 
Accessing memory
 
Basic structure of CS52 program
 
; great comments at the top!
;
 
instruction1
  
; comment
 
instruction2
  
; comment
 
...
 
hlt
 
whitespace before operations/instructions
 
Running the CS52 machine
 
Look at subtract.a52
-
load two numbers from the user
-
subtract
-
print the result
 
CS52 simulator
 
Different windows
Memory (left)
Instruction execution (right)
Registers
I/O and running program
undefined
 
1
st
 R: 
  
first register for comparison
2
nd
 R: 
 
second register in comparison
3
rd
 B:
  
label
undefined
 
beq r3 r0 done
 
What does this do?
 
1
st
 R: 
  
first register for comparison
2
nd
 R: 
 
second register in comparison
3
rd
 B:
  
label
undefined
 
beq r3 r0 done
 
If r3 = 0, branch to the label “done”
if not (else) ic is incremented as normal to
the next instruction
 
1
st
 R: 
  
first register for comparison
2
nd
 R: 
 
second register in comparison
3
rd
 B:
  
label
undefined
 
ble r2 r3 done
 
What does this do?
 
1
st
 R: 
  
first register for comparison
2
nd
 R: 
 
second register in comparison
3
rd
 B:
  
label
undefined
 
ble r2 r3 done
 
If r2 <= r3, branch to the label done
 
1
st
 R: 
  
first register for comparison
2
nd
 R: 
 
second register in comparison
3
rd
 B:
  
label
undefined
 
-
Conditionals
-
Loops
-
Change the order that instructions are
executed
 
CS52 machine execution
 
Basic structure of CS52 program
 
; great comments at the top!
;
 
instruction1
  
; comment
 
instruction2
  
; comment
 
...
label1
 
instruction
  
; comment
 
instruction
  
; comment
label2
 
...
 
hlt
 
end
 
- whitespace before operations/instructions
- labels go here
 
More CS52 examples
 
Look at max_simple.a52
-
Get two values from the user
-
Compare them
-
Use a branch to distinguish between the two cases
-
Goal is to get largest value in r3
-
print largest value
Slide Note
Embed
Share

Delve into the intricacies of computer internals, exploring concepts like CPU, RAM, hard drives, and memory storage. Gain insights into how these components work together to power your device's operations and store vital data effectively.

  • Computer Systems
  • Memory Management
  • CPU
  • RAM
  • Hardware

Uploaded on Feb 23, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CS52 MACHINE David Kauchak CS 52 Spring 2017

  2. Admin Midterm 1 Assignment 3 Assignment 4

  3. Examples from this lecture http://www.cs.pomona.edu/~dkauchak/classes/cs52/examples/cs52machine/

  4. Computer internals

  5. Computer internals simplified CPU RAM What does it stand for? What does it stand for? What does it do? What does it do?

  6. Computer internals simplified CPU RAM (Central Processing Unit, aka the processor ) (Random Access Memory, aka memory or main memory ) Temporary storage Does all the work!

  7. Computer internals simplified the computer hard drive CPU RAM Why do we need a hard drive?

  8. Computer internals simplified the computer hard drive CPU RAM - - Persistent memory RAM only stores data while it has power

  9. Computer simplified the computer hard drive CPU RAM network media drive input devices display

  10. Inside the CPU CPU processor processor: does the work registers: local, fast memory slots registers Why all these levels of memory?

  11. Memory speed operation access time times slower than register access 1 400 ~million ~billion for comparison 1 s 6 min 1 month 30 years register RAM Hard disk google.com 0.3 ns 120 ns 1ms 0.4s

  12. Memory 010101111000101000010010 RAM What is a byte? ?

  13. Memory 01010111 10001010 00010010 RAM byte = 8 bits byte is abbreviated as B My laptop has 16GB (gigabytes) of memory. How many bits is that?

  14. Memory sizes bits byte 8 kilobyte (KB) 2^10 bytes = ~8,000 megabyte (MB) 2^20 =~ 8 million gigabyte (GB) 2^30 = ~8 billion My laptop has 16GB (gigabytes) of memory. How many bits is that?

  15. Memory sizes bits byte 8 kilobyte (KB) 2^10 bytes = ~8,000 megabyte (MB) 2^20 =~ 8 million gigabyte (GB) 2^30 = ~8 billion ~128 billion bits!

  16. Memory address 0 1 2 3 01010111 10001010 00010010 01011010 RAM Memory is byte addressable

  17. Memory address 0 1 2 3 01010111 10001010 00010010 01011010 RAM Memory is organized into words , which is the most common functional unit

  18. Memory address 32-bit words 0 4 8 ... 10101011 10001010 00010010 01011010 11001011 00001110 01010010 01010110 10111011 10010010 00000000 01110100 RAM Most modern computers use 32-bit (4 byte) or 64-bit (8 byte) words

  19. Memory in the CS52 Machine address 16-bit words 0 2 4 ... 10101011 10001010 00010010 01011010 11001011 00001110 RAM We ll use 16-bit words for our model (the CS52 machine)

  20. CS52 machine CPU instruction counter (location in memory of the next instruction in memory) processor ic r0 holds the value 0 (read only) r1 - - general purpose read/write r2 registers r3

  21. instruction counter (location in memory of the next instruction in memory) ic r0 holds the value 0 (read only) r1 - - general purpose read/write r2 r3

  22. CS52 machine instructions CPU processor What types of operations might we want to do (think really basic)? registers

  23. CS52 machine code Four main types of instructions math branch/conditionals memory control the machine (e.g. stop it) 1. 2. 3. 4.

  24. arguments instruction name

  25. arguments instruction name instruction/operation name (always three characters)

  26. arguments instruction name operation arguments R = register (e.g. r0) S = signed number (byte)

  27. arguments instruction name 1st R: 2nd R: 3rd S/R: register where the answer will go register of first operand register/value of second operand

  28. add r1 r2 r3 What does this do? 1st R: 2nd R: 3rd S/R: register where the answer will go register of first operand register/value of second operand

  29. add r1 r2 r3 r1 = r2 + r3 Add contents of registers r2 and r3 and store the result in r1 1st R: 2nd R: 3rd S/R: register where the answer will go register of first operand register/value of second operand

  30. add r2 r1 10 What does this do? 1st R: 2nd R: 3rd S/R: register where the answer will go register of first operand register/value of second operand

  31. add r2 r1 10 r2 = r1 + 10 Add 10 to the contents of register r1 and store in r2 1st R: 2nd R: 3rd S/R: register where the answer will go register of first operand register/value of second operand

  32. add r1 r0 8 neg r2 r1 sub r2 r1 r2 What number is in r2? 1st R: 2nd R: 3rd S/R: register where the answer will go register of first operand register/value of second operand

  33. add r1 r0 8 neg r2 r1 sub r2 r1 r2 r1 = 8 r2 = -8, r1 = 8 r2 = 16 1st R: 2nd R: 3rd S/R: register where the answer will go register of first operand register/value of second operand

  34. Accessing memory sto = save data in register TO memory loa = put data FROM memory into a register sto r1 r2 ; store the contents of r1 to mem[r2] loa r1 r2 ; get data from mem[r2] and put into r1

  35. Accessing memory sto = save data in register TO memory loa = put data FROM memory into a register Special cases: - saving TO (sto) address 0 prints - reading from (loa) address 0 gets input from user

  36. Basic structure of CS52 program ; great comments at the top! ; instruction1 instruction2 ... hlt ; comment ; comment whitespace before operations/instructions

  37. Running the CS52 machine Look at subtract.a52 - load two numbers from the user - subtract - print the result

  38. CS52 simulator Different windows Memory (left) Instruction execution (right) Registers I/O and running program

  39. 1st R: 2nd R: 3rd B: first register for comparison second register in comparison label

  40. beq r3 r0 done What does this do? 1st R: 2nd R: 3rd B: first register for comparison second register in comparison label

  41. beq r3 r0 done If r3 = 0, branch to the label done if not (else) ic is incremented as normal to the next instruction 1st R: 2nd R: 3rd B: first register for comparison second register in comparison label

  42. ble r2 r3 done What does this do? 1st R: 2nd R: 3rd B: first register for comparison second register in comparison label

  43. ble r2 r3 done If r2 <= r3, branch to the label done 1st R: 2nd R: 3rd B: first register for comparison second register in comparison label

  44. - - - Conditionals Loops Change the order that instructions are executed

  45. CS52 machine execution

  46. Basic structure of CS52 program ; great comments at the top! ; instruction1 instruction2 ... label1 instruction instruction label2 ... hlt end ; comment ; comment ; comment ; comment - whitespace before operations/instructions - labels go here

  47. More CS52 examples Look at max_simple.a52 - Get two values from the user - Compare them - Use a branch to distinguish between the two cases - Goal is to get largest value in r3 - print largest value

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#