CPU Emulator Tutorial - PowerPoint PPT Presentation

About This Presentation
Title:

CPU Emulator Tutorial

Description:

CPU Emulator Tutorial. 256 by 512, black & white, simulated screen. ... CPU Emulator Tutorial. Using test scripts. To stop execution, click the Stop button. ... – PowerPoint PPT presentation

Number of Views:79
Avg rating:3.0/5.0
Slides: 14
Provided by: shimons
Category:

less

Transcript and Presenter's Notes

Title: CPU Emulator Tutorial


1
CPU Emulator Tutorial
  • This program is part of the software suite
  • that accompanies the book
  • The Digital Core, by Noam Nisan and Shimon
    Schocken
  • 2003, www.idc.ac.il/csd, forthcoming by MIT Press
  • The software suite was developed by students at
    the
  • Efi Arazi School of Computer Science at IDC
  • Chief Software Architect Yaron Ukrainitz

2
Tutorial Objective
Learn how to use the CPU Emulator for simulating
the execution of machine language programs on the
Hack computer
3
The Computer
  • Address register, used to
  • Select the current RAM location
  • Set the program counter for jumps
  • Load constants under program control

Program counter (16-bit). Selects the current
instruction.
Current instruction is highlighted in the ROM.
Instruction memory (32K). Holds a machine code
program
  • Data memory (32K), used for
  • Data storage
  • Memory-mapped screen
  • Memory-mapped keyboard.

General-purposedata register (16-bit)
Arithmetic logic unit (ALU). Takes two inputs (D
and M/A) and produces one output.
When accessing the RAM, the accessed address is
highlighted.
A simulated keyboard. Must be activated (by
clicking this button) to capture the users
keystrokes on the real keyboard
256 by 512, black white, simulated screen. The
pixels are continuously refreshed from their
respective bits in the memory-mapped screen (RAM).
The current keystroke is displayed here.
4
Loading a program
Select the desired display format.
To locate a specific address, click the search
button and type the desired address.
Clears the ROM.
5
The max program
// This program computes M2 max(M0,
M1) _at_0 DM // D first
number _at_1 DD-M // D first number -
second number _at_output_first DJGT //
if Dgt0 (first is greater) goto output_first _at_1 DM
// D second number _at_output_d 0JMP
// goto output_D (output_first) _at_0
DM // D first
number (output_d) _at_2 MD // M2 D
(greatest number) (infinite_loop) _at_infinite_loop 0
JMP // jump infinitely
  • Example of an assembly program.
  • Computes M2 max(M0, M1)

6
Tests scripts
rom-load max.prg, output-file output, compare-to
max.cmp, output-list RAM0D2.6.2 set RAM0
15, set RAM1 32 repeat 14
ticktack output set PC 0, set RAM0 47, set
RAM1 22 repeat 14 ticktack output
  • Used for automated program testing.
  • Everything that can be done interactively in the
    emulator can be done automatically by the
    script.
  • Written in TDL.

7
Using test scripts
To stop execution, click the Stop button.
To execute step after step repeatedly, click the
Fast Forward button.
To execute one step from the script, click the
Single Step button.
Execution speed is controlled by the speed slider.
To select a script, click the Load Script button
To reset the script to its beginning, click
Rewind.
8
Testing using the default script
The emulator's default script runs the simulated
clock in an infinite loop.
Fast-forward runs the TickTack command repeatedly
until the user clicks Stop. Simulates continuous
program execution with the ability to check the
state of the computer after each instruction.
Single-step performs one TickTack command (single
time-unit), simulating the execution of one
instruction at a time
9
Testing programs using test scripts
rom-load max.prg, output-file output, compare-to
max.cmp, output-list RAM0D2.6.2
RAM1D2.6.2 RAM2D2.6.2 set
RAM0 15, set RAM1 32 repeat 14
ticktack output set PC 0, set RAM0 47, set
RAM1 22 repeat 14 ticktack output
  • A test script is usually designed to test a
    specific program.
  • Can create an output dump of the test results.
  • Along with the script, a comparison file is
    sometimes supplied, to which the output is
    compared.
  • All relevant files (.prg, .tst, .cmp) should be
    in the same directory.

RAM0 RAM1 RAM2 15
32 32
47 22 47
10
Testing programs using test scripts (cont.)
To view the output results or the comparison
file, select output or compare from the
view" box
Load the script
When the script ends, the comparison results are
reported
Program execution stops automatically when a
comparison failure occurs
11
Debugging tool Breakpoints
  • The CPU Emulator recognizes the following
    variables
  • A the contents of the address register.
  • D the contents of the data register.
  • PC the contents of the program counter.
  • RAMi the contents of the RAM at location
    i.
  • ROMi the contents of the ROM at location
    i.
  • Time number of time units since the
    beginning of the script.

To update an existing breakpoint,double click it
Use the and - buttons to add and remove
breakpoints
To open the breakpoints panel, click the
breakpoints button
When the variable reaches the specified value, a
message is displayed.
A breakpoint consists of a variable name and a
specified value
A very powerful debugging tool
12
Writing test scripts
  • Users may write their own test scripts, according
    to specific debugging needs.
  • Usually, the first step of the script should load
    the tested program.
  • The rest of the script may use various scripting
    commands
  • Output tables
  • Loops
  • Breakpoints
  • Variables manipulation
  • Simulation commands Eval, Tick, Tack.
  • Some Built-In chips support special commands. For
    example, the command ROM32K Load ltfile namegt
    loads a program into the ROM32K chip.

Load Computer, Output-file output, Output-list
ARegisterD1.6.1
PCD1.6.1, Breakpoint RAM16K10 137 ROM32K
Load add.prg, Set reset 0, Set RAM16K1
12345, Output Repeat 6 Tick, Tack,
Output Clear-breakpoints
13
Visual options
  • Select one of the animation options
  • Program flow animates only the program flow in
    the ROM.
  • Program data flow animates all program and
    data flow in the computer.
  • No animation program and data flow are not
    animated.
  • When running long programs, choose No animation.
    The GUI will not be updated during simulation,
    increasing execution speed.

To control animation speed,use the speed slider.
  • Select one of the additional view options
  • Script shows the current script.
  • Output shows the output file.
  • Compare shows the comparison file.
  • None Shows the simulated computer only.

Select the desired numeric format Decimal,
Hexadecimal or Binary.
Write a Comment
User Comments (0)
About PowerShow.com