Hardware Simulator Tutorial - University Of Colorado Denver

3y ago
28 Views
2 Downloads
1.78 MB
48 Pages
Last View : 3m ago
Last Download : 3m ago
Upload by : Baylee Stein
Transcription

Hardware Simulator TutorialThis program is part of the software suitethat accompanies the bookThe Elements of Computing Systemsby Noam Nisan and Shimon SchockenMIT Presswww.nand2tetris.orgThis software was developed by students at theEfi Arazi School of Computer Science at IDCChief Software Architect: Yaron UkrainitzHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 1/49

The book’s software suite(All the supplied tools are dual-platform: Xxx.bat startsXxx in Windows, and Xxx.sh starts it in Unix)Simulators(HardwareSimulator, CPUEmulator, VMEmulator): Used to build hardware platforms andexecute programs;This tutorial isabout thehardwaresimulator. Supplied by us.Translators (Assembler, JackCompiler): Used to translate from high-level to low-level; Developed by the students, using the book’sspecs; Executable solutions supplied by us.Other Bin: simulators and translators software; builtIn: executable versions of all the logicgates and chips mentioned in the book; OS: executable version of the Jack OS; TextComparer: a text comparison utility.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 2/49

The Hack computerThe hardware simulator described in thistutorial can be used to build and test manydifferent hardware platforms. In this book, wefocus on one particular computer, called Hack.Hack -- a 16-bit computer equipped with ascreen and a keyboard -- resembles hand-heldcomputers like game machines, PDA’s, andcellular telephones.The first 5 chapters of the book specify theelementary gates, combinational chips,sequential chips, and hardware architecture ofthe Hack computer.All these modules can be built and tested usingthe hardware simulator described in thistutorial.That is how hardware engineers build chipsfor real: first, the hardware is designed,tested, and optimized on a softwaresimulator. Only then, the resultinggate logic is committed to silicon.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 3/49

Hardware Simulation TutorialI. Getting startedII. Test scriptsIII. Built-in chipsIV. Clocked chipsV. GUI-empowered chipsVI. Debugging toolsVII. The Hack PlatformRelevant reading (from “The Elements of Computing Systems”): Chapter 1: Boolean Logic Appendix A: Hardware Description Language Appendix B: Test Scripting LanguageHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 4/49

Hardware Simulation TutorialPart I:Getting StartedHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 5/49

Chip Definition (.hdl file)chipinterface/** Exclusive-or gate. out a xor b */CHIP Xor {IN a, b;OUT out;// Implementation missing.} Chip interface: Name of the chipNames of its input and output pinsDocumentation of the intended chip operationTypically supplied by the chip architect; similar to an API, or a contract.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 6/49

Chip Definition (.hdl file)chipinterface/** Exclusive-or gate. out a xor b */CHIP Xor {IN a, b;OUT out;PARTS:Not(in a, out nota);Not(in b, out notb);And(a a, b notb, out w1);And(a nota, b b, out w2);Or(a w1, b w2, out out);chipimplementation} Any given chip can be implemented in several different ways. This particularimplementation is based on: Xor(a,b) Or(And(a,Not(b)), And(b,Not(a))) Not, And, Or: Internal parts (previously built chips), invoked by the HDLprogrammer nota, notb, w1, w2: internal pins, created and named by the HDL programmer;used to connect internal parts.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 7/49

Loading a ChipNavigate to adirectory and selectan .hdl file.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 8/49

Loading a Chip Names and currentvalues of the chip’soutput pins; Calculated by thesimulator; read-only. Names and current values ofthe chip’s input pins; To change their values, enterthe new values here. Names and current values ofthe chip’s internal pins(used to connect the chip’sparts, forming the chip’s logic); Calculated by the simulator;read-only. Read-only view of the loaded .hdl file; Defines the chip logic; To edit it, use an external text editor.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 9/49

Exploring the Chip Logic1. Click thePARTSkeywordHW Simulator Tutorial www.nand2tetris.org2. A table pops up, showing the chip’s internalparts (lower-level chips) and whether they are: Primitive (“given”) or composite (user-defined) Clocked (sequential) or unclocked (combinational)Tutorial IndexSlide 10/49

Exploring the Chip Logic1. Click any one ofthe chip PARTS2. A table pops up, showing theinput/output pins of the selectedpart (actually, its API), and theircurrent values;A convenient debugging tool.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 11/49

Interactive Chip Testing1. User: changes the values of someinput pins2. Simulator: responds by: Darkening the output and internalpins, to indicate that the displayedvalues are no longer valid Enabling the eval(calculator-shaped) button.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 12/49

Interactive Chip Testing1. User: changes the values of someinput pins2. Simulator: responds by: Darkening the output and internalpins, to indicate that the displayedvalues are no longer validRecalc Enabling the eval(calculator-shaped) button.3. User: Clicked the eval button4. Simulator: re-calculates the valuesof the chip’s internal and outputpins (i.e. applies the chip logic tothe new input values)5. To continue interactive testing,enter new values into the inputpins and click the eval button.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 13/49

Hardware Simulation TutorialPart II:Test ScriptsHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 14/49

Test Scriptsload Xor.hdl,output-file Xor.out,compare-to Xor.cmp,output-list a%B3.1.3b%B3.1.3out%B3.1.3;set a 0,set b 0,eval,output;set a 0,set b 1,eval,output;Etc. a0011 Test scripts: Are used for specifying, automating andInitreplicatingchip testing Are supplied for every chip mentioned inthe book (so you don’t have to write them) Can effect, batch-style, any operation thatSimulation stepcan be done interactively Are written in a simple language describedGeneratedoutput file(Xor.out)in Appendix B of the bookSimulation Cancreatestepan output file that records theresults of the chip testb0101 out0110HW Simulator Tutorial www.nand2tetris.org If the script specifies a compare file, thesimulator will compare the .out file tothe .cmp file, line by line.Tutorial IndexSlide 15/49

Loading a ScriptTo load a new script (.tstfile), click this button;Interactive loading of the chipitself (.hdl file) may not benecessary, since the testscript typically contains a“load chip” command.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 16/49

Script ControlsControlsthe scriptexecutionspeedScript series ofsimulationsteps, eachending witha semicolon.Resetsthe scriptPauses thescript executionMulti-step execution,until a pauseExecutes the nextsimulation stepHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 17/49

Running a ScriptScriptexecutionflowTypical “init” code:1. Loads a chip definition (.hdl) file2. Initializes an output (.out) file3. Specifies a compare (.cmp) file4. Declares an output line format.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 18/49

Running a ScriptComparison of the output lines tothe lines of the .cmp file arereported.ScriptexecutionendsHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 19/49

Viewing Output and Compare FilesHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 20/49

Viewing Output and Compare FilesObservation:This output filelooks like a Xortruth tableConclusion: the chip logic(Xor.hdl) is apparentlycorrect (but not necessarilyefficient).HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 21/49

Hardware Simulation TutorialPart III:Built-in ChipsHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 22/49

Built-In ChipsGeneral A built-in chip has an HDL interface and a Javaimplementation (e.g. here: Mux16.class) The name of the Java class is specified followingthe BUILTIN keyword Built-In implementations of all the chips thatappear in he book are supplied in thetools/buitIn directory.// Mux16 gate (example)CHIP Mux16 {IN a[16],b[16],sel;OUT out[16];BUILTIN Mux16;}Built-in chips are used to: Implement primitive gates (in the computer built in this book: Nand and DFF)Implement chips that have peripheral side effects (like I/O devices)Implement chips that feature a GUI (for debugging)Provide the functionality of chips that the user did not implement for some reasonImprove simulation speed and save memory (when used as parts in complex chips)Facilitate behavioral simulation of a chip before actually building it in HDLBuilt-in chips can be used either explicitly, or implicitly.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 23/49

Explicit Use of Built-in ChipsThe chip is loaded from thetools/buitIn directory (includesexecutable versions of all the chipsmentioned in the book).Standard interface.Built-in implementation.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 24/49

Implicit Use of Built-in Chips/** Exclusive-or gate. out a xor b */CHIP Xor {IN a, b;OUT out;PARTS:Not(in a,out Nota);Not(in b,out Notb);And(a a,b Notb,out aNotb);And(a Nota,b b,out bNota);Or(a aNotb,b bNota,out out);} When any HDL file is loaded, the simulator parses its definition. For each internalchip Xxx(.) mentioned in the PARTS section, the simulator looks for an Xxx.hdlfile in the same directory (e.g. Not.hdl, And.hdl, and Or.hdl in this example). If Xxx.hdl is found in the current directory (e.g. if it was also written by the user), thesimulator uses its HDL logic in the evaluation of the overall chip. If Xxx.hdl is not found in the current directory, the simulator attempts to invoke thefile tools/builtIn/Xxx.hdl instead. And since tools/builtIn includes executable versions of all the chips mentioned inthe book, it is possible to build and test any of these chips before first building theirlower-level parts.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 25/49

Hardware Simulation TutorialPart IV:Clocked Chips(Sequential Logic)HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 26/49

Clocked (Sequential) Chips The implementation of clocked chips is based on sequential logic The operation of clocked chips is regulated by a master clock signal: In our jargon, a clock cycle tick-phase (low), followed by a tock-phase (high) During a tick-tock, the internal states of all the clocked chips are allowed to change,but their outputs are “latched” At the beginning of the next tick, the outputs of all the clocked chips in thearchitecture commit to the new values In a real computer, the clock is implemented by an oscillator; in simulators, clockcycles can be simulated either manually by the user, or repeatedly by a test script.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 27/49

The D-Flip-Flop (DFF) Gate/** Data Flip-flop:* out(t) in(t-1)* where t is the time unit.*/CHIP DFF {IN in;OUT out;Clocked chips Clocked chips include registers,RAM devices, counters, andthe CPU The simulator knows that theloaded chip is clocked whenone or more of its pins isdeclared “clocked”, or one ormore of its parts (or sub-parts,recursively) is a clocked chip In the hardware platform built inthe book, all the clocked chipsare based, directly or indirectly,on (many instances of) built-inDFF gates.BUILTIN DFF;CLOCKED in, out;}DFF: A primitive memory gate that can“remember” a state over clock cycles Can serve as the basic building block ofall the clocked chips in a computer.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 28/49

Simulating Clocked ChipsClocked (sequential) chips are clock-regulated.Therefore, the standard way to test a clocked chipis to set its input pins to some values (as withcombinational chips), simulate the progression ofthe clock, and watch how the chip logic respondsto the ticks and the tocks.For example, consider the simulation of an 8-wordrandom-access memory chip (RAM8).Since this built-in chip alsohappens to be GUI- empowered,the simulator displays its GUI(More about GUI-empoweredchips, soon)A built-in,clockedchip(RAM8) isloadedHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 29/49

Simulating Clocked Chips1. User: enterssome inputvalues andclicks theclock icononce (tick)A built-in,clockedchip(RAM8) isloadedHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 30/49

Simulating Clocked Chips1. User: enterssome inputvalues andclicks theclock icononce (tick)2. Simulator:changes theinternal state ofthe chip, but notethat the chip’soutput pin is notyet effected.A built-in,clockedchip(RAM8) isloadedHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 31/49

Simulating Clocked Chips3. User: clicksthe clock iconagain (tock)1. User: enterssome inputvalues andclicks theclock icononce (tick)2. Simulator:changes theinternal state ofthe chip, but notethat the chip’soutput pin is notyet effected.A built-in,clockedchip(RAM8) isloadedHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 32/49

Simulating Clocked Chips3. User: clicksthe clock iconagain (tock)1. User: enterssome inputvalues andclicks theclock icononce (tick)A built-in,clockedchip(RAM8) isloadedHW Simulator Tutorial www.nand2tetris.org4. Simulator:commits thechip’s output pinto the value ofthe chip’sinternal state.Tutorial Index2. Simulator:changes theinternal state ofthe chip, but notethat the chip’soutput pin is notyet effected.Slide 33/49

Simulating Clocked Chips Using a Test ScriptControls the scriptspeed, and thus thesimulated clock speed,and thus the overallchip execution speedSingle-actiontick-tockDefault script: always loaded whenthe simulator starts running;The logic of the default scriptsimply runs the clock repeatedly;Tick-tocksrepeatedly andinfinitelyHence, executing the default scripthas the effect of causing the clockto go through an infinite train of ticsand tocks.This, in turn, causes all the clockedchip parts of the loaded chip toreact to clock cycles, repeatedly.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 34/49

Hardware Simulation TutorialPart V:GUI-EmpoweredchipsHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 35/49

Built-in Chips with GUI Effects1. A chip whoseparts includebuilt-in chipswas loadedinto thesimulator(ignore the chiplogic for now)HW Simulator Tutorial www.nand2tetris.orgNote: the signature of the internal part doesnot reveal if the part is implemented by abuilt-in chip or by another chip built by theuser. Thus in this example you have tobelieve us that all the parts of this loaded chipare built-in chips.Tutorial IndexSlide 36/49

Built-in Chips with GUI Effects2. If the loaded chip orsome of its parts haveGUI side-effects, thesimulator displays theGUI’s here.1. A chip whoseparts includebuilt-in chipswas loadedinto thesimulatorFor each GUI-empowered built-in chip that appearsin the definition of the loaded chip, the simulatorof thedoes its best to putGUIthe chipGUIbuilt-inin this area.Screen.hdl chipThe actual GUI’s behaviors are then effected by theJava classes that implement the built-in chips.GUI of the built-inKeyboard.hdl chipGUI of the built-inRAM16K.hdl chip(ignore the chiplogic for now)HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 37/49

The Logic of the GUIDemo ChipRAM16K,Screen, &Keyboardare built-inchips with GUIside-effects// Demo of built-in chips with GUI effectsCHIP GUIDemo {IN in[16],load,address[15];OUT out[16];PARTS:RAM16K(in in,load load,address address[0.13],out null);Screen(in in,load load,address address[0.12],out null);Keyboard(out null);} Effect: When the simulator evaluates this chip, it displays the GUI sideeffects of its built-in chip parts Chip logic: The only purpose of this demo chip is to force the simulator toshow the GUI of some built-in chips. Other than that, the chip logic ismeaningless: it simultaneously feeds the 16-bit data input (in) into theRAM16K and the Screen chips, and it does nothing with the keyboard.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 38/49

GUIDemo Chip in Action2. User:runs theclock3. 16 blackpixels aredrawnbeginning inrow 156col 3201. User enters: in –1( 16 1’s in binary) address 5012load 1HW Simulator Tutorial www.nand2tetris.orgExplanation: According to the specification ofthe computer architecture3.describedtheThe chip inlogicroutesscreenthe inarevaluebook, the pixels of the physicalcontinuously refreshed froman 8K RAM- intosimultaneouslythe Screenresident memory map implementedbychipthe andScreen.hdl chip. The exactmappingchipthe RAM16Kbetween this memory chip and the actualpixels is specified in Chapter 5. The refreshprocess is carried out by the simulator.Tutorial IndexSlide 39/49

Hardware Simulation TutorialPart VI:Debugging toolsHW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 40/49

System VariablesThe simulator recognizes and maintains the following variables: Time: the number of time-units (clock-cycles) that elapsed since the scriptstarted running is stored in the variable time Pins: the values of all the input, output, and internal pins of the simulated chipare accessible as variables, using the names of the pins in the HDL code GUI elements: the values stored in the states of GUI-empowered built-in chipscan be accessed via variables. For example, the value of register 3 of theRAM8 chip can be accessed via RAM8[3].All these variables can be used in scripts and breakpoints, for debugging.HW Simulator Tutorial www.nand2tetris.orgTutorial IndexSlide 41/49

Breakpoints2. Previouslydeclaredbreakpoints1. Open thebreakpointspanel3. To update an existingbreakpoint, double-click itThe breakpoints logic: Breakpoint (variable, value) When the specified variable in some3. Add, delete,or updatebreakpointsHW Simulator Tutorial www.nand2tetris.orgbreakpoint reaches its specified value,the script pauses and a message isdisplayed A powerful debugging tool.Tutorial IndexSlide 42/49

Scripts for Testing the Topmost Computer chipload Computer.hdlROM32K load Max.hack,output-file ComputerMax.out,compare-to ComputerMax.cmp,output-list .1RAM16K[2]%D1.7.1;breakpoint PC 10;// First run: compute max(3,5)set RAM16K[0] 3,set RAM16K[1] 5,output;repeat 14 {tick, tock, output;}// Reset the PC (preparing for// second run)set reset 1,tick, tock, output;// Etc.clear-breakpoints;HW Simulator Tutorial www.nand2tetris.org Scripts that test the CPU chip or theComputer chip described in the book usuallystart by loading a machine-language program(.asm or .hack file) into the ROM32K chip The rest of the script typically uses variousfeatures like: Output filesLoopsBreakpointsVariables manipulationtick, tockEtc.All these features are described in AppendixB of the book (Test Scripting Language).Tutorial IndexSlide 43/49

Visual Options Program flow: animates theflow of the currently loadedprogram Program & data flow:animates the flow of the currentprogram and the data flowthroughout the GUI elementsdisplayed on the screen No animation (default):program and data flow are notanimated. Tip: When running programs onthe CPU or Computer chip, anyanimation effects slow down thesimulation considerably.HW Simulator Tutorial www.nand2tetris.orgFormat of displayedpin values: Decimal(default) Hexadecimal BinaryTutorial Index Script: displays thecurrent test script Output: displaysthe generatedoutput file Compare: displaysthe suppliedcomparison file Screen: displaysthe GUI effects ofbuilt-in chips,

The hardware simulator described in this tutorial can be used to build and test many different hardware platforms. In this book, we focus on one particular computer, called Hack. Hack -- a 16-bit computer equipped with a screen and a keyboard -- resembles hand-held computers like game machines, PDA’s, and cellular telephones.

Related Documents:

Farming Simulator 19 Activation Code [addons] V 0.9.1.3 mod for Farming Simulator 19. . If you are passionate about the Farming Simulator 19 Mods as we are then you . Antivirus 2020 Avast Premier Activation Code License Key for Free update 5 . Farming Simulator 19 Money Cheat PC (unlimited money) Looking . Farming Simulator 19 Serial .

CCNA Network Simulator CCNA Exam Simulator CCENT Exam Simulator CCNA ICND2 Exam Simulator CCNP BSCI Exam Simulator 2 Internal memory components of a cisco router ROM : Memory containing micro-code for basic functions to start and maintain the

CCNA Network Simulator CCNA Exam Simulator CCENT Exam Simulator CCNA ICND2 Exam Simulator CCNP BSCI Exam Simulator 2 Internal memory components of a cisco router ROM : Memory containing m

PS320 Fetal Simulator Introduction The PS320 Fetal Simulator (hereafter called the Simulator) is a compact, lightweight, high-performance simulator for use by trained service technicians in fetal monitor testing. Cardiotocographs or Electronic Fetal Monitoring

1 About the Simulator The Life/form Adult Intraosseous Infusion Simulator has been designed to enhance training on an accurate simulator. Palpable landmarks can be used for pinpointing placement where the IO device may be inserted. The Adult I/O Simulator is applicable for use

- HARDWARE USER MANUAL - MANUEL DE L'UTILISATEUR HARDWARE . - HARDWAREHANDLEIDING - MANUALE D'USO HARDWARE - MANUAL DEL USUARIO DEL HARDWARE - MANUAL DO UTILIZADOR DO HARDWARE . - 取扱説明書 - 硬件用户手册. 1/18 Compatible: PC Hardware User Manual . 2/18 U.S. Air Force A -10C attack aircraft HOTAS (**) (Hands On Throttle And .

6.829 NS tutorial Network Simulator Network Simulator (ns-2) 6.829 tutorial Why Network simulation protocol validation controlled experimental conditions low cost in , time, collaboration, complexity Why NS? Provides: protocols: TCP, UDP, HTTP, etc. Traffic Models: Web Traffi

Trustee Joy Harris Jane Gardener Simon Hebditch Trustee Sarah Howell- Davies Jill Batty Cartriona Sutherland treasurer Verity Mosenthal Jenny Thoma Steve Mattingly Trustee Anne Sharpley Lynn Whyte Katy Shaw Trustee Sandra Tait Tina Thorpe Judith Lempriere The position of chair is contested so there will be an election for this post Supporting Statements David Beamish Standing for Chair I .