Mercurial > hg > ede
view docs/lyx/emu.lyx @ 42:792da050d8c4 tip
more dox
author | james <jb302@eecs.qmul.ac.uk> |
---|---|
date | Tue, 22 Apr 2014 14:25:14 +0100 |
parents | a9bf262f557b |
children |
line wrap: on
line source
#LyX 2.0 created this file. For more info see http://www.lyx.org/ \lyxformat 413 \begin_document \begin_header \textclass article \begin_preamble \usepackage[export]{adjustbox}% http://ctan.org/pkg/adjustbox % Resize figures that are too wide for the page. \let\oldincludegraphics\includegraphics \renewcommand\includegraphics[2][]{% \oldincludegraphics[#1,max width=\linewidth,max height=\textheight]{#2} } \end_preamble \use_default_options true \maintain_unincluded_children false \language english \language_package default \inputencoding auto \fontencoding global \font_roman default \font_sans default \font_typewriter default \font_default_family default \use_non_tex_fonts false \font_sc false \font_osf false \font_sf_scale 100 \font_tt_scale 100 \graphics default \default_output_format default \output_sync 0 \bibtex_command default \index_command default \paperfontsize default \spacing single \use_hyperref false \papersize default \use_geometry false \use_amsmath 1 \use_esint 1 \use_mhchem 1 \use_mathdots 1 \cite_engine basic \use_bibtopic false \use_indices false \paperorientation portrait \suppress_date false \use_refstyle 1 \index Index \shortcut idx \color #008000 \end_index \secnumdepth 3 \tocdepth 3 \paragraph_separation indent \paragraph_indentation default \quotes_language english \papercolumns 1 \papersides 1 \paperpagestyle default \tracking_changes false \output_changes false \html_math_output 0 \html_css_as_file 0 \html_be_strict false \end_header \begin_body \begin_layout Part The Emulator \end_layout \begin_layout Section Emulator Design \end_layout \begin_layout Standard \begin_inset Graphics filename /home/jmz/qm/ede/docs/img/emu/ELB816_system.svg display false \end_inset \end_layout \begin_layout Standard Above is a block diagram of a micro-controller with the ELB816 micro-processor at it's core. This is taken from the original ELB816 specification. Implementing a system similar to this as a piece of software is the goal of this section of the project. \end_layout \begin_layout Subsection Memory and Registers \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Graphics filename /home/jmz/qm/ede/docs/img/emu/memory.svg display false \end_inset \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard The micro-controller is based on a Von Neumann architecture and has: \end_layout \begin_layout Itemize A single block of up to 64k byte addressable memory for storing both data and code. \end_layout \begin_layout Itemize Two banks of four 8-bit general purpose registers (R0 to R3). \end_layout \begin_layout Itemize Four 16-bit content specific (PC, SP, DPTR and TMPA) \end_layout \begin_layout Itemize Three 8-bit content specific registers (A, flags and IR) \end_layout \begin_layout Standard The general purpose 8-bit registers and the 16-bit registers can exist as a single sixteen byte block of memory spaces with the following encoding: \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Tabular <lyxtabular version="3" rows="10" columns="5"> <features tabularvalignment="middle"> <column alignment="center" valignment="top" width="0"> <column alignment="center" valignment="top" width="0"> <column alignment="center" valignment="top" width="0"> <column alignment="center" valignment="top" width="0"> <column alignment="center" valignment="top" width="0"> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout MSB \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout MSB \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Description \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout LSB \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout User Accessible? \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 000 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R0 bank 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R0 bank 0 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout General Purpose \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Yes \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 001 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R1 bank 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R1 bank 0 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout General Purpose \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Yes \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 010 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R2 bank 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R2 bank 0 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout General Purpose \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Yes \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 011 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R3 bank 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R3 bank 0 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout General Purpose \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Yes \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 100 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout DPH \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout DPL \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Data Pointer \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Yes \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 101 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout SPH \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout SPL \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Stack Pointer \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Yes \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 110 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout PCH \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout PCL \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Program Counter \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout No \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 111 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout TPH \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout TPL \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Temp Address Register \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout No \end_layout \end_inset </cell> </row> </lyxtabular> \end_inset \end_layout \begin_layout Standard \begin_inset Newpage pagebreak \end_inset \end_layout \begin_layout Standard The 8-bit flag register can exist as a single byte with the following format: \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Tabular <lyxtabular version="3" rows="9" columns="3"> <features tabularvalignment="middle"> <column alignment="center" valignment="top" width="0"> <column alignment="center" valignment="top" width="0"> <column alignment="left" valignment="top" width="10cm"> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Bit \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Flag \end_layout \end_inset </cell> <cell multicolumn="1" alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Description \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout BS \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout User Accessible: Select register bank \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout IE \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout User Accessible: Enable Interrupts when 1 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 2 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout OV \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set to 1 when result of arithmetic operation has even parity \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 3 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout S \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set to 1 when result of arithmetic operation is negative \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 4 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout P \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set to 1 when result of arithmetic operation has even parity \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 5 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout AC \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set to 1 when result of arithmetic operation generates a carry or borrow from bit 3 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 6 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Z \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set to 1 when result of arithmetic operation is Zero \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 7 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout C \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout User Accessible: Set to 1 when result of arithmetic operation generates a carry or borrow from bit 7. Used in rotate through carry operations \end_layout \end_inset </cell> </row> </lyxtabular> \end_inset \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard There is also an 8-bit accumulator register for storing the result of various operations and an 8-bit instruction register for the storing the instruction currently being executed. \end_layout \begin_layout Subsection Control and Execution \end_layout \begin_layout Standard The emulator needs to be controlled externally. This could be via a serial or a file buffer depending on the platform. \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Graphics filename /home/jmz/qm/ede/docs/img/emu/controller.svg display false \end_inset \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Newpage pagebreak \end_inset \end_layout \begin_layout Standard Below is a control protocol which allows and control of the emulators memory and execution. \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Tabular <lyxtabular version="3" rows="15" columns="5"> <features tabularvalignment="middle"> <column alignment="center" valignment="top" width="0"> <column alignment="left" valignment="top" width="2cm"> <column alignment="center" valignment="top" width="1cm"> <column alignment="center" valignment="top" width="1cm"> <column alignment="center" valignment="top" width="3cm"> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Function \end_layout \end_inset </cell> <cell multicolumn="1" alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Arguments \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout CMD byte \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Length \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Description \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout step \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x00 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Execute instruction at PC \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout run \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x01 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Execute instructions from PC until a break point is reached \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout set register \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout register address, value \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x02 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 3 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set a register \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout get register \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout register address \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x03 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 2 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Get the value of a register \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout set flag \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout flag bit, 0 or 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x04 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 3 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Turn a flag bit on or off. LSB = 0, MSB =7 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout get flag \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout flag bit \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x05 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 2 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Get the value of a flag bit \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout write memory block \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout address high, address low, length high, length low, [byte array] \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x06 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 6+ \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set a block of memory of arbitrary length with the bytes in the byte array \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout read memory block \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout address high, address low, length high, length low \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x07 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 5 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Read a block of memory of arbitrary length \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout get A \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x08 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Get value of A \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout get flags \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x09 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Get value of flags \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout get IR \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x0A \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Get Value of IR \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout run for length \end_layout \end_inset </cell> <cell multirow="3" alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout length high, length low \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x0B \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 3 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Run for length number of instruction \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout free run \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x0C \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Run forever - Bypass controller \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout set break point \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout break point index, address high, address low \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 0x0D \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 4 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set 1 of 8 possible break points \end_layout \end_inset </cell> </row> </lyxtabular> \end_inset \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Newpage pagebreak \end_inset \end_layout \begin_layout Standard Here are pseudo-code representations of the execution control functions. \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset listings lstparams "basicstyle={\ttfamily},frame=tb,framexbottommargin=1em,framextopmargin=1em,keywordstyle={\color{blue}},tabsize=4" inline false status open \begin_layout Plain Layout step ( ) \end_layout \begin_layout Plain Layout get PC \end_layout \begin_layout Plain Layout IR = byte in memory at PC \end_layout \begin_layout Plain Layout decode and execute instruction \end_layout \begin_layout Plain Layout end \end_layout \begin_layout Plain Layout \end_layout \begin_layout Plain Layout run ( ) \end_layout \begin_layout Plain Layout while PC is not a break point: \end_layout \begin_layout Plain Layout step( ) \end_layout \begin_layout Plain Layout end \end_layout \begin_layout Plain Layout \end_layout \begin_layout Plain Layout run for length ( length ) \end_layout \begin_layout Plain Layout counter = 0 \end_layout \begin_layout Plain Layout while counter != length: \end_layout \begin_layout Plain Layout step( ) \end_layout \begin_layout Plain Layout \end_layout \begin_layout Plain Layout free run ( ): \end_layout \begin_layout Plain Layout loop forever: \end_layout \begin_layout Plain Layout step( ) \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Newpage pagebreak \end_inset \end_layout \begin_layout Section Emulator Implementation \end_layout \begin_layout Standard The Emulator is written in pure C89 to ensure as much cross compiler compatibili ty as possible. It source code consists of the following files: \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Tabular <lyxtabular version="3" rows="6" columns="2"> <features tabularvalignment="middle"> <column alignment="center" valignment="top" width="0"> <column alignment="left" valignment="top" width="8cm"> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout File \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Description \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout main.c \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Initializes the emulator at boot and controls execution \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout iset.h \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Declares a function for each mnemonic in the instruction set. Declares a 256 byte function pointer table \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout iset.c \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Contains a function for each mnemonic in the instruction set \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout mem.h \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Declares variables for the various memory structures. Declares memory access function definitions \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout mem.c \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Contains memory access functions \end_layout \end_inset </cell> </row> </lyxtabular> \end_inset \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Subsection main.c \end_layout \begin_layout Standard In this file the 256 byte instruction table is filled with pointers to the functions in iset.c. This file also contains the control interface function and execution control functions. None of these functions take any arguments or return any data. \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard Below is a list of the functions that appear in this file. \end_layout \begin_layout Standard \begin_inset Tabular <lyxtabular version="3" rows="7" columns="2"> <features tabularvalignment="middle"> <column alignment="center" valignment="top" width="0"> <column alignment="left" valignment="top" width="8cm"> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Function \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Description \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout snd \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Puts a character into the serial or file output buffer \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout rcv \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Get a character from the serial or file input buffer \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout step \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Execute the instruction pointed to by PC \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout run \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Execute instructions until a break point is reached \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout controller \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Get character from input buffer and deal with accordingly \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout main \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Make sure free run isn't enabled at boot, call controller function forever \end_layout \end_inset </cell> </row> </lyxtabular> \end_inset \end_layout \begin_layout Standard \begin_inset Newpage pagebreak \end_inset \end_layout \begin_layout Standard Below is the format of the instruction pointer table initialized in this file. Each item in the table is a pointer to a function. \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard According to the program Cdecl, in \begin_inset Quotes eld \end_inset human language \begin_inset Quotes erd \end_inset , it's declaration is: \begin_inset Quotes eld \end_inset declare ops as array 256 of pointer to function (void) returning void \begin_inset Quotes erd \end_inset . \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard The number of the pointers position in the table is the opcode for the instructi on that the function being pointed to deals with. \end_layout \begin_layout Standard \begin_inset listings lstparams "basicstyle={\ttfamily},frame=tb,framexbottommargin=1em,framextopmargin=1em,keywordstyle={\color{blue}},tabsize=4" inline false status open \begin_layout Plain Layout void (*ops[256])(void) = { \end_layout \begin_layout Plain Layout NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, \end_layout \begin_layout Plain Layout SET, CLR, SET, CLR, SET, CLR, CPL, CPL, \end_layout \begin_layout Plain Layout XCSD, SFA, LAF, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout MOV, MOV, MOV, MOV, MOV, MOV, MOV, MOV, \end_layout \begin_layout Plain Layout ANL, ANL, ANL, ANL, ANL, ANL, ANL, ANL, \end_layout \begin_layout Plain Layout ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, \end_layout \begin_layout Plain Layout XRL, XRL, XRL, XRL, XRL, XRL, XRL, XRL, \end_layout \begin_layout Plain Layout RL, RLC, RR, RRC, INC, DEC, INC, DEC, \end_layout \begin_layout Plain Layout ADD, ADD, ADD, ADD, ADD, ADD, ADD, ADD, \end_layout \begin_layout Plain Layout ADDC, ADDC, ADDC, ADDC, ADDC, ADDC, ADDC, ADDC, \end_layout \begin_layout Plain Layout SUB, SUB, SUB, SUB, SUB, SUB, SUB, SUB, \end_layout \begin_layout Plain Layout SUBB, SUBB, SUBB, SUBB, SUBB, SUBB, SUBB, SUBB, \end_layout \begin_layout Plain Layout PJMP, PJMP, PJMP, PJMP, PJMP, PJMP, PJMP, PJMP, \end_layout \begin_layout Plain Layout PCALL, PCALL, PCALL, PCALL, PCALL, PCALL, PCALL, PCALL, \end_layout \begin_layout Plain Layout DJNZ, DJNZ, DJNZ, DJNZ, CJNE, CJNE, CJNE, CJNE, \end_layout \begin_layout Plain Layout LJMP, LCALL, RET, RETI, SJMP, JMP, JMP, CJNE, \end_layout \begin_layout Plain Layout JZ, JNZ, JC, JNC, JPO, JPE, JS, JNS, \end_layout \begin_layout Plain Layout PUSH, PUSH, PUSH, PUSH, PUSH, PUSH, PUSH, PUSH, \end_layout \begin_layout Plain Layout POP, POP, POP, POP, POP, POP, POP, POP, \end_layout \begin_layout Plain Layout MUL, DIV, DA, NOP, IN, OUT, INT, HLT \end_layout \begin_layout Plain Layout }; \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Newpage pagebreak \end_inset \end_layout \begin_layout Subsection iset.c/h \end_layout \begin_layout Standard For every mnemonic in the ELB816 instruction set there is a function in these files. These are the functions that are pointed to in the instruction table that is filled in main.c. The functions behave according to their description in the ELB816 specification [1]. \end_layout \begin_layout Subsection mem.c/h \end_layout \begin_layout Standard In mem.h the memory structure of the emulator is defined in accordance with how it was described in the previous section. mem.c contains the following functions to facilitate access to this memory. \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Tabular <lyxtabular version="3" rows="11" columns="4"> <features tabularvalignment="middle"> <column alignment="center" valignment="top" width="0"> <column alignment="center" valignment="top" width="0"> <column alignment="center" valignment="top" width="0"> <column alignment="left" valignment="top" width="6cm"> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Function \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Arguments \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Returns \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Description \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout get_flag \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout flag \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 byte \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Get the value of a flag (can be 0 or 1) \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout set_flag \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout flag, on \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set a flag to 0 if on == 0, else set flag to 1 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout set_zp \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout value \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set zero and parity flags based on value \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout get_wide \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout register \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 2 bytes \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Get the value of a 16-bit register \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout set_wide \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout register, value \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set the value of a 16-bit register \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout inc_pc \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout n \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Increment the PC by n \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout fetch \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 byte \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout return the byte in memory at PC, increment PC \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout fetch_wide \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 2 bytes \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout return the 2 bytes in memory at PC, increment PC by 2 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout get_reg \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout register \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 1 byte \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Get the value of an 8-bit register \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout set_reg \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout register, value \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout - \end_layout \end_inset </cell> <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Set the value of an 8-bit register \end_layout \end_inset </cell> </row> </lyxtabular> \end_inset \end_layout \begin_layout Standard \begin_inset Newpage pagebreak \end_inset \end_layout \begin_layout Standard The various register access functions use different register encoding schemes. These are in the tables below. \end_layout \begin_layout Itemize get_wide/set_wide \end_layout \begin_layout Standard \begin_inset Tabular <lyxtabular version="3" rows="5" columns="2"> <features tabularvalignment="middle"> <column alignment="center" valignment="top" width="0"> <column alignment="center" valignment="top" width="0"> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Register \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Encoding \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout DPTR \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 00 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout SP \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 01 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout PC \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 10 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout TMPA \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 11 \end_layout \end_inset </cell> </row> </lyxtabular> \end_inset \end_layout \begin_layout Itemize get_reg/set_reg - These values correspond to the way registers are encoded into the last 3-bits of many of the ELB816 instructions. \end_layout \begin_layout Standard \begin_inset Tabular <lyxtabular version="3" rows="9" columns="2"> <features tabularvalignment="middle"> <column alignment="center" valignment="top" width="0"> <column alignment="center" valignment="top" width="0"> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Register \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout Encoding \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R0 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 000 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R1 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 001 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R2 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 010 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout R3 \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 011 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout DPH \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 100 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout DPL \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 101 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout SPH \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 110 \end_layout \end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout SPL \end_layout \end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none"> \begin_inset Text \begin_layout Plain Layout 111 \end_layout \end_inset </cell> </row> </lyxtabular> \end_inset \end_layout \begin_layout Section Porting to Intel MCS-51 \end_layout \begin_layout Standard In order make this code compile for an 8052 using Keil C51 a few changes to were needed. These are detailed below. \end_layout \begin_layout Subsection main.c \end_layout \begin_layout Standard In the PC version of the emulator, the function table is declared as: \end_layout \begin_layout Standard \begin_inset listings lstparams "basicstyle={\ttfamily},frame=tb,framexbottommargin=1em,framextopmargin=1em,language=C" inline false status open \begin_layout Plain Layout FUNCTION_TABLE const iset \end_layout \end_inset \end_layout \begin_layout Standard Since the instruction set is 256 bytes long and the 8052 only has 256 bytes of internal RAM, this data structure must be redeclared to exist in code memory space. \end_layout \begin_layout Standard \begin_inset listings lstparams "basicstyle={\ttfamily},frame=tb,framexbottommargin=1em,framextopmargin=1em,language=C" inline false status open \begin_layout Plain Layout FUNCTION_TABLE const code iset \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Newpage pagebreak \end_inset \end_layout \begin_layout Standard The PC version of the emulator uses a file buffer to communicate with the debugger. On the 8052 communication uses a serial interface. Because of this the snd() functions differ. \end_layout \begin_layout Standard On the PC \end_layout \begin_layout Standard \begin_inset listings lstparams "basicstyle={\ttfamily},frame=tb,framexbottommargin=1em,framextopmargin=1em,language=C" inline false status open \begin_layout Plain Layout snd(BYTE c) { \end_layout \begin_layout Plain Layout fp = fopen("out", "a"); \end_layout \begin_layout Plain Layout fputc(c, fp); \end_layout \begin_layout Plain Layout fclose(fp); \end_layout \begin_layout Plain Layout } \end_layout \end_inset \end_layout \begin_layout Standard Becomes on the 8052, simply: \end_layout \begin_layout Standard \begin_inset listings lstparams "basicstyle={\ttfamily},frame=tb,framexbottommargin=1em,framextopmargin=1em,language=C" inline false status open \begin_layout Plain Layout snd(BYTE c) { \end_layout \begin_layout Plain Layout putchar(c); \end_layout \begin_layout Plain Layout } \end_layout \end_inset \end_layout \begin_layout Standard The 8052's serial point also needs to be configures at the start of main execution like this: \end_layout \begin_layout Standard \begin_inset listings lstparams "basicstyle={\ttfamily},frame=tb,framexbottommargin=1em,framextopmargin=1em,language=C" inline false status open \begin_layout Plain Layout SCON = 0x50; * SCON - mode 1, 8-bit UART, enable rcvr \end_layout \begin_layout Plain Layout TMOD |= 0x20; * TMOD - timer 1, mode 2, 8-bit reload \end_layout \begin_layout Plain Layout TH1 = 0xE8; * TH1 - reload value for 1200 baud@12MHz \end_layout \begin_layout Plain Layout TR1 = 1; * TR1 - timer 1 run \end_layout \begin_layout Plain Layout TI = 1; * TI - set TI to send first char of UART \end_layout \end_inset \end_layout \begin_layout Subsection mem.h \end_layout \begin_layout Standard The 8052 development board available during this project had 32K of external RAM available. This meant the size of the emulators Von Neumann memory space had to be halved and declared to exist in external data memory. \end_layout \begin_layout Standard On the PC: \end_layout \begin_layout Standard \begin_inset listings lstparams "basicstyle={\ttfamily},frame=tb,framexbottommargin=1em,framextopmargin=1em,keywordstyle={\color{blue}},language=C" inline false status open \begin_layout Plain Layout BYTE mem[0x10000]; \end_layout \end_inset \end_layout \begin_layout Standard On the 8052 \end_layout \begin_layout Standard \begin_inset listings lstparams "basicstyle={\ttfamily},frame=tb,framexbottommargin=1em,framextopmargin=1em,keywordstyle={\color{blue}},language=C" inline false status open \begin_layout Plain Layout BYTE xdata mem[0x8000]; \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Newpage pagebreak \end_inset \end_layout \begin_layout Section Emulator Testing \end_layout \begin_layout Standard The assemblers memory structures and access functions were tested by using the access function to set the memory structures to know values, and then request the values back and write them to a file. The file was then inspected by hand. The test files and results can be found in the Supporting Material. \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard The emulator could be more rigorously tested in conjunction with the debugger and assembler. Below is a pseudo-code representation of an automated test procedure that could be implemented with the debug class in python. \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout \backslash bigskip \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset listings lstparams "basicstyle={\ttfamily},frame=tb,framexbottommargin=1em,framextopmargin=1em,language=C" inline false status open \begin_layout Plain Layout for instruction in instruction set: \end_layout \begin_layout Plain Layout reset emulator memory state \end_layout \begin_layout Plain Layout assemble instruction \end_layout \begin_layout Plain Layout write instruction to memory \end_layout \begin_layout Plain Layout execute instruction \end_layout \begin_layout Plain Layout \end_layout \begin_layout Plain Layout get all registers \end_layout \begin_layout Plain Layout get all flags \end_layout \begin_layout Plain Layout get any affected memory cells \end_layout \begin_layout Plain Layout \end_layout \begin_layout Plain Layout if and only if expected register changes occoured: \end_layout \begin_layout Plain Layout register test passed \end_layout \begin_layout Plain Layout if and only if expected flag changes occoured: \end_layout \begin_layout Plain Layout flag test passed \end_layout \begin_layout Plain Layout if expected memory modification occoured: \end_layout \begin_layout Plain Layout memory test passed \end_layout \end_inset \end_layout \end_body \end_document