jb302@26: #LyX 2.0 created this file. For more info see http://www.lyx.org/ jb302@26: \lyxformat 413 jb302@26: \begin_document jb302@26: \begin_header jb302@26: \textclass article jb302@26: \use_default_options true jb302@26: \maintain_unincluded_children false jb302@26: \language english jb302@26: \language_package default jb302@26: \inputencoding auto jb302@26: \fontencoding global jb302@26: \font_roman lmodern jb302@26: \font_sans lmss jb302@27: \font_typewriter lmtt jb302@27: \font_default_family sfdefault jb302@26: \use_non_tex_fonts false jb302@26: \font_sc false jb302@26: \font_osf false jb302@26: \font_sf_scale 100 jb302@26: \font_tt_scale 100 jb302@26: jb302@26: \graphics default jb302@26: \default_output_format default jb302@26: \output_sync 0 jb302@26: \bibtex_command default jb302@26: \index_command default jb302@26: \paperfontsize default jb302@26: \spacing single jb302@26: \use_hyperref false jb302@26: \papersize default jb302@26: \use_geometry false jb302@26: \use_amsmath 1 jb302@26: \use_esint 1 jb302@26: \use_mhchem 1 jb302@26: \use_mathdots 1 jb302@26: \cite_engine basic jb302@26: \use_bibtopic false jb302@26: \use_indices false jb302@26: \paperorientation portrait jb302@26: \suppress_date false jb302@26: \use_refstyle 1 jb302@26: \index Index jb302@26: \shortcut idx jb302@26: \color #008000 jb302@26: \end_index jb302@26: \secnumdepth 3 jb302@26: \tocdepth 3 jb302@26: \paragraph_separation indent jb302@26: \paragraph_indentation default jb302@26: \quotes_language english jb302@26: \papercolumns 1 jb302@26: \papersides 1 jb302@26: \paperpagestyle default jb302@26: \tracking_changes false jb302@26: \output_changes false jb302@26: \html_math_output 0 jb302@26: \html_css_as_file 0 jb302@26: \html_be_strict false jb302@26: \end_header jb302@26: jb302@26: \begin_body jb302@26: jb302@26: \begin_layout Title jb302@26: EDE: ELB816 Development Environment jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Author jb302@26: James Bowden (110104485) jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Abstract jb302@26: The ELB816 Development Environment consists of an assembler, emulator and jb302@26: debugger for the ELB816 microprocessor system. jb302@27: This report details the design and usage of each of its elements. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset Newpage newpage jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@27: \begin_inset CommandInset toc jb302@27: LatexCommand tableofcontents jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset Newpage newpage jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Part jb302@27: Introduction and Specification jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset ERT jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@27: jb302@27: jb302@27: \backslash jb302@27: bigskip jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Section jb302@27: Motivations jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: The ELB816 architecture is designed to be a jb302@27: \begin_inset Quotes eld jb302@27: \end_inset jb302@27: jb302@27: simple to understand 8-bit microprocessor system to help learn about microproces jb302@27: sor electronics. jb302@27: \begin_inset Quotes erd jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset ERT jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: jb302@27: \backslash jb302@27: bigskip jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: The combination of an ELB816 emulator, debugger and assembler could be used jb302@27: as a set of tools for learning or teaching microprocessor programming without jb302@27: the intricacies of real-world commercial microprocessors getting in the jb302@27: way of a fundamental understanding of the subject. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset ERT jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: jb302@27: \backslash jb302@27: bigskip jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: A PC based emulator would allow students to quickly develop and debug programs jb302@27: written in a simple assembly language on any modern desktop or laptop and jb302@27: an MCS-51 port running on an 8052 would allow students to test programs jb302@27: in an actual circuit. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Section jb302@27: Project Aims jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Itemize jb302@27: Develop an assembler for the ELB816 assembly language. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Itemize jb302@27: Develop an emulated programmable microprocessor system based on the ELB816 jb302@27: architecture. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Itemize jb302@27: Develop a debugger that allows interactive debugging of programs running jb302@27: on the emulator. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Section jb302@27: Methodology jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Subsection jb302@26: Assembler jb302@26: \end_layout jb302@26: jb302@27: \begin_layout Description jb302@27: Language: Python jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Description jb302@27: Priority: First jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: The assembler will be developed before anything else so that it can subsequently jb302@27: be used to assemble test programs during development of the emulator. jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset Newpage newpage jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@27: \begin_layout Subsection jb302@26: Emulator jb302@26: \end_layout jb302@26: jb302@27: \begin_layout Description jb302@27: Language: C jb302@26: \end_layout jb302@26: jb302@27: \begin_layout Description jb302@27: Priority: Second jb302@27: \end_layout jb302@27: jb302@26: \begin_layout Standard jb302@27: The emulator will use only standard libraries in order to ensure it is portable jb302@27: between compilers and platforms. jb302@27: Specifically GCC for x86 and Keil C51 for Intel MCS-51. jb302@27: The emulator will first be developed on Linux to facilitated rapid development. jb302@27: It will be ported to MCS-51 once it is complete jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Subsection jb302@26: Debugger jb302@26: \end_layout jb302@26: jb302@27: \begin_layout Description jb302@27: Language: C/Python jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Description jb302@27: Priority: Second jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: The debug interface will be developed along side the emulator. jb302@27: It will consist of a simple text based interface built into the emulator jb302@27: that will read commands using C's jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: stdio.h jb302@27: \end_layout jb302@27: jb302@26: \end_inset jb302@26: jb302@27: library. jb302@27: This means that on Linux the commands will be issued using jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: STDIN jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: and on the MCS-51 version they will be issued over a serial interface. jb302@27: Python will be used to provide a cleaner interface for common debug procedures jb302@27: such as writing programs to memory and setting break-points. jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset ERT jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: jb302@27: \backslash jb302@27: bigskip jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: The remainder of this report is split into three parts, one for each component jb302@27: of the project, and will attempt to demonstrate the design and usage of jb302@27: each of these components. jb302@27: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset Newpage newpage jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Part jb302@26: Assembler jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: The assembler is written in pure Python 2 using only the standard library. jb302@26: It assembles the assembly the language described in the ELB816 specification jb302@26: with a few minor differences. jb302@26: These differences are: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: In-line arithmetic must be wrapped in curved brackets eg. jb302@26: start with '(' and end with ')'. jb302@26: This is a limitation of the design of the program and to change it would jb302@26: require a large amount of code to be re-written. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: The only directives that have been implemented are jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: ORG jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: , jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: EQU jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: , jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: DB jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: and jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: DS jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: . jb302@26: The other directives listed in the specification have not been implemented, jb302@26: but there omission is only due to time constraints and they could easily jb302@26: be implemented in a later version. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: Macros have not been implemented also due to time constraints. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: The assembler consists of two files: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: language.py jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: which contains the language definition in an index and some functions to jb302@26: help encode instructions. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: assembler.py jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: which contains the first and second pass functions and handles opening jb302@26: source files and writing binary files. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@27: The following sections details the design and behavior of the assembler. jb302@26: However it must be noted that these are abstract and high level descriptions jb302@26: that do not fully explain minor routines, but give an overview of the entire jb302@26: process. jb302@26: The full source code is attached in the Appendix and should be referenced jb302@26: for a deeper understanding of the program's operation. jb302@27: The final section is a short programmers manual demonstrating the assembler's jb302@27: features. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset Newpage newpage jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Section jb302@26: Data Structures jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: reserved arguments jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: This structure contains a list of string representations of the reserved jb302@26: word arguments for the instruction set. jb302@26: These all equate to registers or register pointers. jb302@26: The full list is as follows: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily},captionpos=b,frame=tb,framexbottommargin=1em,framextopmargin=1em,keywordstyle={\color{blue}},tabsize=4" jb302@26: inline false jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: a, c, bs, ie, flags, jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: r0, r1, r2, r3, jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: dptr, dpl, dph, jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: sp, sph, spl, jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: @a+pc, @a+dptr, @dptr jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: relative instructions jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: This structure contains a list of string representations of the mnemonics jb302@26: of instructions that use relative addressing. jb302@26: The full list is as follows: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily},captionpos=b,frame=tb,framexbottommargin=1em,framextopmargin=1em,keywordstyle={\color{blue}},tabsize=4" jb302@26: inline false jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: djnz, cjne, sjmp, jz, jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jnz, jc, jnc, jpo, jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jpe, js, jns jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: instruction index jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: This structure contains an index of all possible instructions in the instruction jb302@26: set, along with the the corresponding opcode and instruction width. jb302@26: This is implemented using a combination of Python's dictionary, tuple and jb302@26: list objects. jb302@26: Its structure is demonstrated below: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily},captionpos=b,frame=tb,framexbottommargin=1em,framextopmargin=1em,keywordstyle={\color{blue}},tabsize=4" jb302@26: inline false jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@30: mnemonic: (arg type, arg type, ...): [opcode, width] jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: Each mnemonic has an entry in the parent index which returns another index jb302@26: of possible argument formats for that mnemonic with their corresponding jb302@26: opcode and length. jb302@26: Argument types can be either be one of the reserved arguments or one of jb302@26: the following values: jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: address jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: , jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: pointer jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: , jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: data jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: or jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: label jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: . jb302@26: Width is represented in number of bytes, ie. jb302@26: jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: width = 3 jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: means 1 byte of opcode and 2 bytes of arguments. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: label index jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: This structure is used to store an index of label definitions. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: equate index jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: This structure is used to store an index of equated strings. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset Newpage newpage jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Section jb302@26: Functions jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: first_pass(source file) jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: This function pre-processes a source file and stores it in a format containing jb302@26: the necessary data for the jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: second_pass() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: function to assemble it. jb302@26: It processes labels and jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: EQU jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: directives by storing strings and their corresponding values in indexes jb302@26: and replacing any subsequent appearances of the string with the value. jb302@26: It prepares jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: ORG jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: and jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: DB jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: statements for the jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: second_pass() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: . jb302@26: It uses the jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: tokenize() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: function to determine the argument symbols and operand bit string. jb302@26: Finally it uses the jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: instruction index jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: to determine the instruction width. jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: second_pass(asm, label index) jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: This function takes the pre-processed assembly code and jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: label index jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: output by jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: first_pass() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: as input. jb302@26: First it checks for jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: ORG jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: and jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: DB jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: statements and handles them if necessary. jb302@26: Then it replaces any labels that were used before they were defined and jb302@26: therefore not replaced on by jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: first_pass() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: . jb302@26: It uses the jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: instruction index jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: to determine the opcode and the width of the instruction, then it writes jb302@26: the opcode and operand to the file. jb302@26: If the combined width of the opcode and operand is greater than the instruction jb302@26: width the function raises an error. jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: tokenize(mnemonic, arguments) jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: This function processes an instruction in order to produce a hashable symbol jb302@26: that represents the format of its arguments. jb302@26: This symbol is used to look up opcodes in the jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: instruction index jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: . jb302@26: It also detects string representations of numbers in the arguments and jb302@26: stores a C type struct representation of the operands to be returned along jb302@26: with the symbol. jb302@26: It does this with the help of the jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: stoi() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@27: function and Python's jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: struct jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: module . jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Itemize jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: stoi(string) jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: This function is a general purpose function that is actually used throughout jb302@26: the code, although mainly in the jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: tokenize() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: function. jb302@26: It takes a string as an input and tries to convert it to an integer using jb302@26: Pythons integer representation syntax. jb302@26: It can recognize decimal, octal, hexadecimal and binary numbers which are jb302@26: denoted with different prefixes. jb302@26: If it receives a string it can not represent as an integer it returns the jb302@26: string 'NaN', (Not a Number) jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset ERT jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \backslash jb302@26: bigskip jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: Below is an abstract representation of each functions logical process. jb302@26: The jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: first_pass() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: and jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: second_pass() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: are represented in pseudo-code, however jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: stoi() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: and jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\ttfamily}" jb302@26: inline true jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: tokenize() jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: are more easily understood when represented as flowcharts. jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset Newpage newpage jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Subsection jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: first_pass jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\small\ttfamily},captionpos=b,frame=tb,framexbottommargin=3em,framextopmargin=3em,keywordstyle={\color{blue}},language=Python,showstringspaces=false,tabsize=4" jb302@26: inline false jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: first_pass(source file): jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: address = 0 jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: for statement in source file: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: remove comments jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: for word in statement: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: if word is in equate index: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: replace word with equated value jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: else if word is in label index: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: replace word with address at label jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: if first word == 'org' jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: address = second word jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: else if last character of first word == ':': jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: remove ':' jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: add word = address to label index jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: next statement jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: else if second word == 'equ' jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: add first word = third word to equate index jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: next statement jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: mnemonic = first word jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: arguments = [second word ... jb302@26: last word] jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: symbol, constant = tokenize(arguments) jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: if mnemonic == 'db': jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: address = address + width of constant jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: next statement jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: width = instruction index[mnemonic][symbol][width] jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: address = address + width jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: append [mnemonic, argument, symbol, constant] to asm jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: return asm, label index jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \begin_inset Newpage newpage jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Subsection jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: second_pass jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset listings jb302@26: lstparams "basicstyle={\small\ttfamily},breaklines=true,captionpos=b,frame=tb,framexbottommargin=3em,framextopmargin=3em,keywordstyle={\color{blue}},language=Python,tabsize=4" jb302@26: inline false jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: second_pass(file, asm, label index): jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: address = 0 jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: for line in asm: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: file offset = address jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: mnemonic, arguments, symbol, constant = line jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: if mnemonic == 'org': jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: address = first argument jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: next line jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: else if mnemonic == 'db': jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: write constant to file jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: address = address + width of constant jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: next line jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: for argument in arguments: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: if argument is a label: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: replace argument with address at label jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: symbol, data = tokenize(argument) jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: append data to constant jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: op, width = instruction index[mnemonic][symbol] jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: write op to file jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: if width of constant - width + 1 > 0: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: raise error jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: else if: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: write constant to file jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: address = address.+ width jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: return file jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \begin_inset Newpage newpage jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Subsection jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: tokenize jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset ERT jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \backslash jb302@26: bigskip jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset Graphics jb302@26: filename /home/jmz/qm/ede/doc/images/assembler/tokenize.svg jb302@27: scale 57 jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset Newpage newpage jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Subsection jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: stoi jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset ERT jb302@26: status open jb302@26: jb302@26: \begin_layout Plain Layout jb302@26: jb302@26: jb302@26: \backslash jb302@26: bigskip jb302@26: \end_layout jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Description jb302@26: \begin_inset Graphics jb302@26: filename /home/jmz/qm/ede/doc/images/assembler/stoi.svg jb302@26: scale 70 jb302@26: jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Standard jb302@26: \begin_inset Newpage newpage jb302@26: \end_inset jb302@26: jb302@26: jb302@26: \end_layout jb302@26: jb302@26: \begin_layout Section jb302@27: Assembly language manual jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset Newpage newpage jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Part jb302@27: Emulator jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Section jb302@27: Core microprocessor emulation jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: The core of the emulator is written in C using only standard libraries. jb302@27: It executes the machine code output by the assembler according to the ELB816 jb302@27: specification. jb302@27: It consists of the following files: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Itemize jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: iset.c jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: and jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: iset.h jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: These files contain the emulator instruction functions and function look-up jb302@27: table. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Itemize jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: mem.c jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: and jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: mem.h jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: These files contain the emulators memory structure and memory access functions. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Itemize jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: emu.c jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: This file contains the program's jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: main() jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: function. jb302@27: It initializes the emulator and executes the programs fetch/decode/execute jb302@27: cycle. jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset ERT jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: jb302@27: \backslash jb302@27: bigskip jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: Below is a high level description of the content of each of these files jb302@27: which should demonstrate how the emulator works. jb302@27: There is also a large amount of material relevant to the emulator's design jb302@27: in the appendix, which will be referenced when applicable. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Subsection jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: iset.c jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: and jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: iset.h jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: Each mnemonic in the ELB816 instruction set has a function defined in these jb302@27: files. jb302@27: Each function is responsible for execution of all the instructions that jb302@27: use its corresponding mnemonic. jb302@27: The function look-up table is an array of pointers to these functions, jb302@27: where a pointer's position in the list corresponds to the opcode of the jb302@27: instruction to be executed. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset ERT jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: jb302@27: \backslash jb302@27: bigskip jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset Newpage newpage jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Subsection jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: mem.c jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: and jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: mem.h jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: The figures bellow illustrate the emulator's memory layout as defined in jb302@27: the jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: mem.h jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: header file. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset ERT jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: jb302@27: \backslash jb302@27: bigskip jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: mem.c jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: contains functions that can be used to access this memory from the rest jb302@27: of the code. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset Newpage newpage jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Subsection jb302@27: \begin_inset listings jb302@27: lstparams "basicstyle={\ttfamily}" jb302@27: inline true jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: emu.c jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: This file contains the emulator's set-up and control procedures. jb302@27: It includes all of the projects header files and controls the execution jb302@27: of the functions contained in them. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset ERT jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: jb302@27: \backslash jb302@27: bigskip jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: It first executes a number of initialization procedures and then passes jb302@27: control over to the main fetch/decode/execute cycle. jb302@27: This procedure is shown below as a flowchart. jb302@27: To understand this it you must be familiar with C's function pointer syntax. jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset ERT jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: jb302@27: \backslash jb302@27: bigskip jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset ERT jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: jb302@27: \backslash jb302@27: centerline{ jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \begin_inset Graphics jb302@27: filename /home/jmz/qm/ede/doc/images/emulator/fetch_decode_exe.svg jb302@27: scale 70 jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \begin_inset ERT jb302@27: status open jb302@27: jb302@27: \begin_layout Plain Layout jb302@27: jb302@27: } jb302@27: \end_layout jb302@27: jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset Newpage newpage jb302@27: \end_inset jb302@27: jb302@27: jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Section jb302@27: Peripherals jb302@27: \end_layout jb302@27: jb302@27: \begin_layout Standard jb302@27: \begin_inset Newpage newpage jb302@27: \end_inset jb302@27: jb302@27: jb302@26: \end_layout jb302@26: jb302@26: \end_body jb302@26: \end_document