data hierarchy
play

Data hierarchy fast registers & slow memory & arithmetic - PowerPoint PPT Presentation

Programs Data Data hierarchy fast registers & slow memory & arithmetic no computation on-chip o ff -chip o ff -machine RAM Hard Registers Cache(s) Network random-access drive memory central processing unit (


  1. Programs Data ≡

  2. Data hierarchy fast registers & 
 slow memory & 
 arithmetic no computation on-chip o ff -chip o ff -machine RAM 
 Hard 
 Registers Cache(s) Network random-access drive memory central processing unit ( CPU ) program + data live here Cost & Speed

  3. Our focus: registers and RAM registers are 
 RAM 
 like variables Registers random-access memory central processing unit ( CPU ) program + data live here

  4. This is just for your enjoyment! 
 strobe D in For CS 42, you don’t need to be able to 
 Quiz! & (1)#What#are# A 's#three#inputs,# strobe for next instruction flip-flops and#how#is# A 's#output#used?# understand or recreate this design. (2)#What#is#the#output#of# R #+# Q out 0 0 0 0 0 1 0 1 PC # what#2#things#is#it#used#for?# 8 address bits (3)#Why#are#there#50#and#not# read enable 50#million#on3chip#registers?# RAM # (4)#What#wire(s)#ensure#that# strobe for all the#value#4#gets#added?# IR bits 1 0 0 1 1 1 0 0 IR # (5)#In#the#next#clock#tick,#line#3 # goes#low#(0)#and#line#4#goes# high#(1).#What#wires#ensure# 8 bit instruction that#the#output#of#the#addition# is#placed# back% into#register#3?# R " (6)# Bug! #How#do#we#Oix#it!?!# A " 1 # decode instruction 2 # clock# 3 # 4 #5 # strobe to finish old value of Reg3 = 7 instruction 0 1 1 1 Reg3" Ripple3 add#4#to#reg3 ! 7+4 Adder # 1 0 0 1 1 1 0 0 IR # 4 output bits 1 0 1 1 the#same "Reg3" Instruction # Argument#1 # Argument#2 # new value of Reg3 = 11 a#constant# the#register# 10#means#"add"# Reg3" 4 " Don't#hand#this#in #

  5. What counts as a problem? Decision problems on 
 finite, bitstring inputs. What kinds of problems can computers solve? Can sequential logic solve 
 all the problems that a DFA 
 can? How about a Turing Machine? What counts as a computer?

  6. Harvey Mudd Miniature Machine (H MMM ) registers are 
 RAM 
 like variables Registers random-access memory central processing unit ( CPU ) program + data live here 16 registers 
 256 memory 
 locations For now, think of this as: 
 We can have programs with no 
 more than 256 lines of code.

  7. H MMM operations: reading and writing read r1 r1 = user input write r1 print r1’s value to screen

  8. H MMM programs Must have line numbers and must end with a halt instruction 00 read r1 01 write r1 02 halt

  9. H MMM operations: arithmetic Translate these Hmmm operations into a language you understand. setn r1 42 add r3 r2 r1 addn r1 42 sub r3 r2 r1 copy r2 r1 neg r3 r2 mul r3 r2 r1 Bonus questions (if you have time): Use addn to infer the range of numbers that can be added to a register. What happens if you forget halt ? Why do you think there is an addn and and add instruction? Firstname Lastname T. 9 / 25 (Your response) tinyurl.com/hmc-hmmm

  10. Data operations are like assignments Read from le fu to right numbers in range 
 -128 to 127 setn r1 42 r1 = 42 addn r1 42 r1 = r1 + 42 copy r1 r2 r1 = r2 add r3 r1 r2 r3 = r1 + r2 sub r3 r1 r2 r3 = r1 - r2 neg r3 r1 r3 = -r1 mul r3 r1 r2 r3 = r1 * r2 div r3 r1 r2 r3 = r1 / r2 mod r3 r1 r2 r3 = r1 % r2

  11. Jumps control the program’s behavior Goto a particular line (possibly a fu er comparing a register value to 0 ) jumpn 42 goto line 42 jeqzn r1 42 if r1 == 0, goto line 42 jnezn r1 42 if r1 != 0, goto line 42 jgtzn r1 42 if r1 > 0, goto line 42 jltzn r1 42 if r1 < 0, goto line 42

  12. Longer Hmmm programs What common function does Write a Hmmm program that reads this program compute? a positive integer value, then writes the factorial of that value. 00 read r1 Use only arithmetic, assignments, 
 01 read r2 and jumps. 02 sub r3 r1 r2 03 nop # “do nothing” 04 jgtzn r3 7 Why is there a nop instruction? 05 write r1 Can you come up with some good 06 jumpn 8 strategies for writing Hmmm programs? 07 write r2 08 halt tinyurl.com/hmc-hmmm

  13. Factorial (iterative version) # get the input (r1) from the user 0 read r1 # The program works by multiplying r1 * (r1 - 1) * (r1 - 2) * ... * 1, # storing the result in r2, then printing r2 # (We'll assume, rather than check, that r1 is non-negative.) # initialize answer (r2) to be 1 1 setn r2 1 # while r1 > 0: # multiply the result (r2) by the current value of the counter (r1) # decrement r1 2 jeqzn r1 6 # loop condition: enter loop if r1 != 0 3 mul r2 r2 r1 4 addn r1 -1 5 jumpn 2 # go back to the top of the loop # write the result 6 write r2 7 halt

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend