⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spim.tex

📁 Spim软件的一些源码。其中有Xspim的
💻 TEX
📖 第 1 页 / 共 5 页
字号:
ex}, {\tt re}, {\tt l}, {\tt ru}, {\tt s}, {\tt p}.  More dangerouscommands, such as {\tt reinitialize}, require a longer prefix.\subsubsection{X-Window Interface}\begin{figure}  \centerline{\psfig{figure=xinterface.id,height=4.5in}}  \caption{X-window interface to SPIM.}  \label{fig:xinterface}\end{figure}The X version of SPIM, {\tt xspim}, looks different, but shouldoperate in the same manner as {\tt spim}.  The X window has five panes(see Figure~\ref{fig:xinterface}).  The top pane displays the contentsof the registers.  It is continually updated, except while a programis running.The next pane contains the buttons that control the simulator:\begin{itemize}  \item [] {\bf quit}\newline Exit from the simulator.  \item [] {\bf load}\newline Read a source file into memory.  \item [] {\bf reload}\newline Reinitialize memory and then reload thelast file read with {\bf load}.  \item [] {\bf run}\newline Start the program running.  \item [] {\bf step}\newline Single-step through a program.  \item [] {\bf clear}\newline Reinitialize registers or memory.  \item [] {\bf set value}\newline Set the value in a register ormemory location.  \item [] {\bf print}\newline Print the value in a register or memorylocation.  \item [] {\bf breakpoints}\newline Set or delete a breakpoint or listall breakpoints.  \item [] {\bf help}\newline Print a help message.  \item [] {\bf terminal}\newline Raise or hide the console window.  \item [] {\bf mode}\newline Set SPIM operating modes.\end{itemize}The next two panes display the memory contents.  The top one showsinstructions from the user and kernel text segments.\footnote{Theseinstructions are real---not pseudo---MIPS instructions.  SPIMtranslates assembler pseudoinstructions to 1--3 MIPS instructionsbefore storing the program in memory.  Each source instruction appearsas a comment on the first instruction to which it is translated.} Thefirst few instructions in the text segment are startup code ({\tt\_\_start}) that loads {\tt argc} and {\tt argv} into registers andinvokes the {\tt main} routine.The lower of these two panes displays the data and stack segments.Both panes are updated as a program executes.The bottom pane is used to display messages from the simulator.  Itdoes not display output from an executing program.  When a programreads or writes, its IO appears in a separate window, called theConsole, which pops up when needed.\subsection{Surprising Features}Although SPIM faithfully simulates the MIPS computer, it is asimulator and certain things are not identical to the actual computer.The most obvious differences are that instruction timing and thememory systems are not identical.  SPIM does not simulate caches ormemory latency, nor does it accurate reflect the delays for floatingpoint operations or multiplies and divides.Another surprise (which occurs on the real machine as well) is that apseudoinstruction expands into several machine instructions.  Whensingle-stepping or examining memory, the instructions that you see areslightly different from the source program.  The correspondencebetween the two sets of instructions is fairly simple since SPIM doesnot reorganize the instructions to fill delay slots.\subsection{Assembler Syntax}\label{sec:syntax}Comments in assembler files begin with a sharp-sign ({\tt \#}).Everything from the sharp-sign to the end of the line is ignored.Identifiers are a sequence of alphanumeric characters, underbars ({\tt\_}), and dots ({\tt .}) that do not begin with a number.  Opcodes forinstructions are reserved words that are {\bf not} valid identifiers.Labels are declared by putting them at the beginning of a linefollowed by a colon, for example:\begin{verbatim}        .data  item: .word 1        .text        .globl main             # Must be global  main: lw $t0, item\end{verbatim}Strings are enclosed in double-quotes ({\tt "}).  Special charactersin strings follow the C convention:\begin{verbatim}    newline        \n    tab            \t    quote          \"\end{verbatim}SPIM supports a subset of the assembler directives provided by theMIPS assembler:\begin{description}  \item [] {\tt .align n}\newline Align the next datum on a $2^n$ byteboundary.  For example, {\tt .align 2} aligns the next value on a wordboundary.  {\tt .align 0} turns off automatic alignment of {\tt.half}, {\tt .word}, {\tt .float}, and {\tt .double} directives untilthe next {\tt .data} or {\tt .kdata} directive.  \item [] {\tt .ascii str}\newline Store the string in memory, but donot null-terminate it.  \item [] {\tt .asciiz str}\newline Store the string in memory andnull-terminate it.  \item [] {\tt .byte b1, ..., bn}\newline Store the $n$ values insuccessive bytes of memory.  \item [] {\tt .comm sym size}\newline Allocate {\em size} bytes ofdata segment for symbol {\em sym}.  \item [] {\tt .data <addr>}\newline The following data items shouldbe stored in the data segment.  If the optional argument {\em addr\/}is present, the items are stored beginning at address {\em addr\/}.  \item [] {\tt .double d1, ..., dn}\newline Store the $n$ floatingpoint double precision numbers in successive memory locations.  \item [] {\tt .extern sym size}\newline Declare that the datumstored at {\tt sym} is {\tt size} bytes large and is a global symbol.This directive enables the assembler to store the datum in a portionof the data segment that is efficiently accessed via register {\tt\$gp}.  \item [] {\tt .float f1, ..., fn}\newline Store the $n$ floatingpoint single precision numbers in successive memory locations.  \item [] {\tt .globl sym}\newline Declare that symbol {\tt sym} isglobal and can be referenced from other files.  \item [] {\tt .half h1, ..., hn}\newline Store the $n$ 16-bitquantities in successive memory halfwords.  \item [] {\tt .kdata <addr>}\newline The following data items shouldbe stored in the kernel data segment. If the optional argument {\emaddr\/} is present, the items are stored beginning at address {\emaddr\/}.  \item [] {\tt .ktext <addr>}\newline The next items are put in thekernel text segment.  In SPIM, these items may only be instructions orwords (see the {\tt .word} directive below). If the optional argument{\em addr\/} is present, the items are stored beginning at address{\em addr\/}.  \item [] {\tt .label sym}\newline Declare that symbol {\tt sym} is alabel.  \item [] {\tt .lcomm sym size}\newline Allocate {\em size} bytesfor symbol {\em sym} in the portion of the data segment that can beaccessed via register {\tt \$gp}.  \item [] {\tt .space n}\newline Allocate $n$ bytes of space in thecurrent segment (which must be the data segment in SPIM).  \item [] {\tt .set noat}\newline Permit the program to refer to the{\tt \$at} register explicitly, and forbid SPIM from generating pseudoinstructionsthat modify {\tt \$at}.  \item [] {\tt .set at}\newline Forbid the program from referring to the{\tt \$at} register explicitly, and permit SPIM to generate pseudoinstructionsthat modify {\tt \$at} (the default).  \item [] {\tt .text <addr>}\newline The next items are put in theuser text segment.  In SPIM, these items may only be instructions orwords (see the {\tt .word} directive below).  If the optional argument{\em addr\/} is present, the items are stored beginning at address{\em addr\/}.  \item [] {\tt .word w1, ..., wn}\newline Store the $n$ 32-bitquantities in successive memory words.\end{description}SPIM does not distinguish various parts of the data segment ({\tt.data}, {\tt .rdata}, and {\tt .sdata}).\subsection{System Calls}\label{sec:scall}\begin{table}  \small  \begin{center}  \begin{tabular}{|l|c|l|l|}    \hline     \multicolumn{1}{|c|}{\bf Service} &	{\bf System Call Code} &	\multicolumn{1}{|c|}{\bf Arguments} &	\multicolumn{1}{|c|}{\bf Result} \\     \hline     \hline      print\_int & 1 & {\tt \$a0} = integer & \\      print\_float & 2 & {\tt \$f12} = float & \\      print\_double & 3 & {\tt \$f12} = double & \\      print\_string & 4 & {\tt \$a0} = string & \\      read\_int & 5 & & integer (in {\tt \$v0}) \\      read\_float & 6 & & float (in {\tt \$f0}) \\      read\_double & 7 & & double (in {\tt \$f0}) \\      read\_string & 8 & {\tt \$a0} = buffer, {\tt \$a1} = length & \\      sbrk & 9 & {\tt \$a0} = amount & address (in {\tt \$v0}) \\      exit & 10 & & \\      print\_character & 11 & {\tt \$a0} = character & \\      read\_character & 12 & & character (in {\tt \$v0}) \\      open & 13 &  {\tt \$a0} = filename, & file descriptor (in {\tt \$v0}) \\           &    &  \ \ \ \ {\tt \$a1} = flags, {\tt \$a2} = mode & \\      read & 14 & {\tt \$a0} = file descriptor, & bytes read (in {\tt \$v0}) \\           &    &  \ \ \ \ {\tt \$a1} = buffer, {\tt \$a2} = count & \\      write & 15 & {\tt \$a0} = file descriptor,& bytes written (in {\tt \$v0}) \\            &    & \ \ \ \ {\tt \$a1} = buffer, {\tt \$a2} = count &                               \\      close & 16 & {\tt \$a0} = file descriptor & 0 (in {\tt \$v0}) \\      exit2 & 17 & {\tt \$a0} =  value &  \\     \hline  \end{tabular}  \end{center}  \caption{System services.}  \label{tab:syscall}\end{table}SPIM provides a small set of operating-system-like services throughthe system call ({\tt syscall}) instruction.  To request a service, aprogram loads the system call code (see Table~\ref{tab:syscall}) intoregister {\tt \$v0} and the arguments into registers {\tt\$a0}$\ldots${\tt \$a3} (or {\tt \$f12} for floating point values).System calls that return values put their result in register {\tt\$v0} (or {\tt \$f0} for floating point results).  For example, toprint ``{\tt the answer = 5}'', use the commands:\begin{verbatim}        .data  str:  .asciiz "the answer = "        .text        li $v0, 4        # system call code for print_str        la $a0, str      # address of string to print        syscall          # print the string        li $v0, 1        # system call code for print_int        li $a0, 5        # integer to print        syscall          # print it\end{verbatim}{\tt print\_int} is passed an integer and prints it on the console.{\tt print\_float} prints a single floating point number. {\ttprint\_double} prints a double precision number.  {\tt print\_string}is passed a pointer to a null-terminated string, which it writes tothe console. {\tt print\_character} prints a single ASCII character.{\tt read\_int}, {\tt read\_float}, and {\tt read\_double} read anentire line of input up to and including the newline.  Charactersfollowing the number are ignored.  {\tt read\_string} has the samesemantics as the Unix library routine {\tt fgets}.  It reads up to$n-1$ characters into a buffer and terminates the string with a nullbyte.  If there are fewer characters on the current line, it readsthrough the newline and again null-terminates the string.  {\ttread\_character} reads a single ASCII character.  {\bfWarning:} programs that use these syscalls to read from the terminalshould not use memory-mapped IO (see Section~\ref{sec:IO}).{\tt sbrk} returns a pointer to a block of memory containing $n$ additionalbytes.  This pointer is word aligned. {\tt exit} stops a program fromrunning. {\tt exit2} stops the program from running and takes an argument,which is the value that {\tt spim} or {\tt xspim} uses in its call on {\ttexit}.{\tt open}, {\tt read}, {\tt write} and {\tt close} behave the same asthe Unix system calls of the same name.  They all return $-1$ onfailure.\section{Description of the MIPS R2000}\label{sec:mips}\begin{figure}  \centerline{\psfig{figure=mips.id,height=4in}}  \caption{MIPS R2000 CPU and FPU}  \label{fig:mips}\end{figure}A MIPS processor consists of an integer processing unit (the CPU) anda collection of coprocessors that perform ancillary tasks or operateon other types of data such as floating point numbers (seeFigure~\ref{fig:mips}).  SPIM simulates two coprocessors.  Coprocessor0 handles traps, exceptions, and the virtual memory system.  SPIMsimulates most of the first two and entirely omits details of thememory system.  Coprocessor 1 is the floating point unit.  SPIMsimulates most aspects of this unit.\subsection{CPU Registers}\begin{table}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -